Two way server : Server « Network « Perl






Two way server

    

use IO::Socket;

$server = IO::Socket::INET->new
(
    LocalPort => 1111,
    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) {
        while ($line = <$client>) {
            print "Read this from client: $line";
        }
    } else {
        while ($line = <>) {
            print $client $line; 
        }
    }    
}

   
    
    
    
  








Related examples in the same category

1.Time server
2.The server and the client are on the same machine
3.Simple server
4.Socket answer
5.Socket pair
6.Socket server waiting for clients
7.Read from server
8.Send data from client to server
9.Forking Servers