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();