Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Fork and pipe

by kschwab (Priest)
on Aug 30, 2002 at 16:32 UTC ( #194162=note: print w/replies, xml ) Need Help??

in reply to Fork and pipe

You may want to have a look at the built-in Tk mechanisms to handle I/O within the Gui event loop.

This would allow the incoming sockets to be dealt with without forking. See:

Update The docs do mention some unsavory behavior on Win32...bah. Sorry. I have little Win32 experience or I wouldn't have suggested it.

Replies are listed 'Best First'.
Re: Re: Fork and pipe
by gri6507 (Deacon) on Aug 30, 2002 at 19:58 UTC
    The following code still seems unresponsive (can't click on button, and label is not refreshed). This must be a windows thing.

    use Tk; use IO::Socket; use strict; my $sock; my $port = 7076; my $time = 60; my $mw = MainWindow->new; my $button = $mw->Button(-text=>"click", -command=>sub{exit;})->place(-x=>0,-y=>0); my $l = $mw->Label(-text=>"$time")->place(-x=>0,-y=>50); $mw->update; $sock = new IO::Socket::INET ( LocalHost => 'localhost', LocalPort => $port, Proto => 'tcp', Listen => 1, Reuse => 1, #Timeout => 0.1, ); die "Could not create socket: $!\n" unless $sock; $mw->fileevent($sock,'readable',[\&readit]); $mw->repeat(100,sub{$l->configure(-text=>$time--);$mw->update;}); MainLoop; sub readit{ my $new_sock = $sock->accept(); my $in = <$new_sock>; print "received $in\n"; }
Re: Re: Fork and pipe
by gri6507 (Deacon) on Aug 30, 2002 at 17:38 UTC
    Looking at the documentation, Tk::fileevent would be excellent in my case. However, I cannot get it to work in a noneblocking manner. The execution seems to stop while processing the $mainwindow->fileevent($socket,'readable',[\&some_sub]); line. Have you seen an example with a socket read fileevent callback? (that works on Windows?). Thanks
      I must retract this statement. The blocking was happening NOT a the fileevent line, but the line just above that, $socket->accept(); (duhhh). I need a break :-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://194162]
and a kettle whistles...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2018-05-27 03:40 GMT
Find Nodes?
    Voting Booth?