You do not use fileevent. I constructed a simple toy server and client, they work just ok.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.