use IO::Socket; my $sock = new IO::Socket::INET ( LocalHost => 'localhost', LocalPort => '7070', Proto=>'tcp', Listen=>1, Reuse=>1, ); my $new_sock = $sock->accept(); $i=0; while(1){ print $new_sock "HIII CALLER!\n"; print $new_sock "stop reading ,caller!\n"; while(<$new_sock>){ print $_; if($_ == "stop reading ,receiver!\n"){ last; }; } } close($sock); #### use IO::Socket; $sock =0; while(!$sock){ $sock = new IO::Socket::INET ( PeerAddr => 'localhost', PeerPort => '7070', Proto => 'tcp', ); } die "Could not create socket: $!\n" unless $sock; while(1){ print $sock "HIIII RECEIVER!\n"; print $sock "stop reading ,receiver!\n"; while(<$sock>){ print $_; if($_ == "stop reading ,caller!\n"){ last; }; } }; close($sock);