Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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.


Comment on Re: Fork and pipe
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 :-)
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"; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (14)
As of 2015-07-06 20:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (83 votes), past polls