in reply to Sockets
Turn on autoflushing. It works OK like this on my NT box (fork() is there, too - kudos to ActiveState for fork implementation!).
#!/usr/bin/perl use IO::Socket; $SIG{CHLD} = sub {wait()}; # turn autoflushing on $| = 1; $main_sock = new IO::Socket::INET( LocalHost => '127.0.0.1', LocalPort => 6666, Listen => 5, Proto => 'tcp', Reuse => 1) or die $!; $line = ""; while ($new_sock = $main_sock->accept()) { $pid = fork(); die "Cannot fork: $!" unless defined($pid); if ($pid == 0) { # Child process while (defined ($buf = <$new_sock>)) { print "Client said: $buf\n"; } exit(0); } else { $line = <STDIN>; print $new_sock "$line"; } }
NOTE: (added to node later) - sorry - I did not get your point right - the script does not remedy the problem you talked about - however, turning autoflushing on is a good idea for networking code, anyway.
Christian Lemburg
Brainbench MVP for Perl
http://www.brainbench.com
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: RE: Sockets
by meonkeys (Chaplain) on Apr 24, 2001 at 13:57 UTC | |
by clemburg (Curate) on Apr 24, 2001 at 14:26 UTC | |
by meonkeys (Chaplain) on Apr 24, 2001 at 14:42 UTC |