use strict; use IO::Socket; my $remote = IO::Socket::INET->new( Proto => 'tcp', # protocol PeerAddr=> '127.0.0.1', # Address of server PeerPort=> "1426", # port of server Timeout => 90 ) or die "$!"; $remote->autoflush(1); for (my $i = 0; $i < 100 ; $i++) { $remote->send("Test \n"); # Send to Server my $line ; $remote->recv($line,256); # Receive echo from server print $line. "\n"; } close $remote; # Close socket #### use IO::Socket qw(:DEFAULT :crlf); use IO::File; use constant PIDFILE => "/tmp/prefork.pid"; use constant PREFORK_CHILDREN => 3; my $port = shift || 1426; my $socket = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $port, Listen => 5, Reuse => SO_REUSEADDR, Type => SOCK_STREAM ) or die "Can't create listen socket: $!"; # create PID file, initialize logging, and go into background #init_server(PIDFILE); make_new_child() for (1..PREFORK_CHILDREN); exit 0; sub make_new_child { #my $child = launch_child(); my $child = fork; return if $child; do_child($socket); # child handles incoming connections exit 0; } sub do_child { my $socket = shift; while (1) { local $/ = "\n"; next unless my $c = $socket->accept; handle_connection($c); close $c; } close $socket; } sub handle_connection { my $x = shift; my $sz = <$x>; print $x "Testing\n"; }