my $server = new IO::Socket::INET();
while(my $client = $server->accept())
{
next if fork;
my $line = <$client>;
print $client "You said: $line\m";
exit;
}
The server goes in to an infinte loop accepting new client connections, when it receives a connection it creates a new $client containg that connection and the forks. The parent goes back to waiting for the connection while the child reads a line from the client and prints one back to it. You could use various ->read() methods, but I find it much simpler to just read based on new lines. |