Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: Curses::UI loop dilemma

by Anonymous Monk
on Mar 25, 2013 at 22:32 UTC ( #1025408=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Curses::UI loop dilemma
in thread Curses::UI loop dilemma

Hi, I'm trying to do something similar to this. I am using Curses::UI to implement a ticket like system where new tickets comes in from users via UDP and it will update the Curses:UI:Listbox.

I tried to take the same route and and rather than using the $cui->mainloop(); from Curses:UI, I put it into my own server so that it can update the UI without blocking. But it seems when I do that, I lose the Curses:UI listbox functionality of having a scrollbox, being able to move up/down the list, etc; since everytime I try to run doupdate(); when a new UDP comes in, the program exits...

#!/usr/bin/perl use strict; use warnings; use IO::Socket; use Curses::UI; my ($sock, $data, $clienthost, $maxlen, $port); $maxlen = 1024; $port = 3711; my @array; my $cui = Curses::UI->new(-mouse_support => 0,-read_timeout => 0); my $win = $cui->add('window_id', 'Window'); my $listbox = $win->add('Tickets', 'Listbox', -border => 1, -title => 'Items', -vscrollbar => 1, ); $cui->{-read_timeout} = 0; $cui->set_binding( sub{ exit }, "\cQ" ); $cui->draw(); $sock = IO::Socket::INET->new(LocalPort => $port, Type => SOCK_DGRAM, Proto => 'udp') or die "Could not open socket!\n"; while (1) { $cui->focus(undef, 1); # 1 = forced focus $sock->recv($data, $maxlen); chomp($data); my $req = $data; my($port, $ipaddr) = sockaddr_in($sock->peername); $clienthost = gethostbyaddr($ipaddr, AF_INET); $listbox->insert_at(\@array, "New ticket from ".$clienthost.": ".$re +q); $sock->send("We have received your ticket: $req"); $listbox->focus(); $cui->draw; # doupdate(); $cui->do_one_event();


Comment on Re^3: Curses::UI loop dilemma
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1025408]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2015-07-05 08:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (61 votes), past polls