radagast has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use IO::Socket; $SIG{CHLD} = sub {wait()}; $main_sock = new IO::Socket::INET( LocalHost => 'b5', 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"; } }
My question is with regards to non-blocking. When I first connect, I can write from my telnet session to my server no problem but I can only send one thing I type from my server. Somehow it is not getting to the print $new_sock "$line"; statement. I'm doing forking because it seemed less hairier than using IO::Select. This code has been borrowed and modified from Advanced Perl Programming.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Sockets
by Fastolfe (Vicar) on Nov 03, 2000 at 18:58 UTC | |
by meonkeys (Chaplain) on Apr 24, 2001 at 15:03 UTC | |
RE: Sockets
by Corion (Patriarch) on Nov 03, 2000 at 18:27 UTC | |
RE: Sockets
by clemburg (Curate) on Nov 03, 2000 at 18:39 UTC | |
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 | |
Re: Sockets
by fundflow (Chaplain) on Nov 03, 2000 at 18:28 UTC | |
Re: Sockets
by meonkeys (Chaplain) on Apr 24, 2001 at 13:51 UTC |