Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Listening Socket in Tk

by Errto (Vicar)
on May 08, 2005 at 00:07 UTC ( [id://454944]=note: print w/replies, xml ) Need Help??


in reply to Listening Socket in Tk

You can do this with a non-blocking socket and Tk's repeat method (see Tk::after). This is untested, but something like it should work:
sub checksocket { my ($sock) = @_; my $data; $sock->read($data, $nnn) # replace $nnn with number of bytes you +want or return; # no data read # do something with $data here } my $mw = MainWindow->new; # set up your Tk widgets here my $sock = IO::Socket::INET->new(PeerAddr => 'host:port', Proto => 'tcp', Blocking => 0); # set non-blocking mode my $after = $mw->repeat(500, # set to appropriate number of milis sub { checksocket($sock) } ); MainLoop;
This will cause Tk to do its usual thing, except that it will interrupt the event loop every however-many milliseconds to call your subroutine, which will attempt to read data from the socket in non-blocking mode.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-16 17:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found