Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/local/bin/perl -w #use strict; use IO::Socket; #my ($socket, $child_pid, $line) = (); $socket = IO::Socket::INET->new ( PeerAddr => '123.123.123.123', # changed ip for post =) PeerPort => '5123', Proto => "tcp", Type => SOCK_STREAM ) or die "Could not create client: $!\n"; unless (defined($child_pid = fork())) {die "Can not fork: $!\n"}; if ($child_pid) { while ($line = <>) { print $socket $line; } } else { while ($line = <$socket>) { print "SERVER: $line"; } }
#!/usr/local/bin/perl -w #use strict; use IO::Socket; #my ($server, $client, $child_pid, $line) = (); $server = IO::Socket::INET->new ( LocalPort => '5123', Type => SOCK_STREAM, Reuse => 1, Listen => 5 ) or die "Could not create server: $!\n"; while ($client = $server->accept()) { unless (defined($child_pid = fork())) {die "Can not fork: $!\n +"}; if ($child_pid) { print "CLIENT: $client\n"; while ($line = <$client>) { print "CLIENT: $line"; } } else { while ($line = <>) { print $client $line; } } }
Edit: BazB, added code tags.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: To Fork for Not to Fork
by iburrell (Chaplain) on Nov 10, 2003 at 22:05 UTC | |
|
Re: To Fork for Not to Fork
by pg (Canon) on Nov 10, 2003 at 21:12 UTC | |
by chromatic (Archbishop) on Nov 10, 2003 at 22:56 UTC | |
by pg (Canon) on Nov 10, 2003 at 23:38 UTC | |
by tilly (Archbishop) on Nov 11, 2003 at 00:55 UTC | |
|
Re: To Fork for Not to Fork
by castaway (Parson) on Nov 11, 2003 at 08:03 UTC | |
|
Re: To Fork for Not to Fork
by BUU (Prior) on Nov 11, 2003 at 07:58 UTC | |
|
Re: To Fork for Not to Fork
by Anonymous Monk on Nov 11, 2003 at 04:36 UTC |