use IO::Socket; use warnings; use strict; #use Term::ReadKey; my $flush = 1; my $sock = new IO::Socket::INET ( LocalHost => 'PK5', LocalPort => '7070', Proto => 'tcp', Listen => 1, # max concurrent caller Reuse => 1, ); die "Could not create socket: $!\n" unless $sock; print "SERVER Waiting for client connection on port 7070\n"; my $new_sock = $sock->accept(); # $new_sock->autoflush(1); # so output gets there right away my $peer_address = $new_sock->peerhost(); my $peer_port = $new_sock->peerport(); # $new_sock->blocking(0); # $| = 1; print "Accepted New Client Connection From : $peer_address, $peer_port\n"; my $pid = fork(); if (not defined $pid) {print "resources not available.\n";} elsif ($pid == 0) { # child, receiver while(<$new_sock>) { print $_; if($_ eq "end\n"){last;} } exit(0); } else { # parent, sender while(<>){ # $new_sock->flush; # ReadMode 1; print $new_sock $_; # $new_sock->flush; if($_ eq "end\n"){last;} } waitpid($pid,0); }