Server:
#!/usr/bin/perl use IO::Socket::INET; use IO::Select; use strict; use warnings; my $listen = new IO::Socket::INET(Listen => 1, LocalPort => 8889); my $sel = new IO::Select($listen); { my $fh; print STDERR "1\n"; sleep 1 until ($fh) = $sel->can_read; print STDERR "2\n"; my $new = $listen->accept; $sel->add($new); print STDERR $new->sockhost," 2.5\n"; } while (1){ print STDERR "3\n"; foreach my $fh ($sel->can_write){ print STDERR "4\n"; print $fh rand(100),"\n" or die "4:$!\n"; } sleep 1; }
Client:
#!/usr/bin/perl use Tk; use Tk::Listbox; use IO::Socket::INET; use strict; use warnings; my $top = MainWindow->new; my $f = $top->Frame->pack; my $lb = $f->Listbox()->pack; my $socket = IO::Socket::INET->new(PeerAddr => 'localhost', PeerPort => 8889, Proto=>'tcp') or die "Cannot connect: $!\n"; $top->fileevent($socket, readable => sub { chomp(my $line = <$socket>); print STDERR "$line"; $lb->insert('end',":$line"); # $lb->insert('end',$line) or die; }); MainLoop;
First, run the server. Then, run the client, it will connect to the server and it will start sending it numbers that will be shown in the listbox.
In reply to Re^5: Perl - TK - Listbox insertion problem
by choroba
in thread Perl - TK - Listbox insertion problem
by k0rn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |