#!/usr/bin/perl -w use IO::Socket; use Net::hostent; # for OO version of gethostbyaddr my ($kidpid); $PORT = 9000; # pick something not in use $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $PORT, Listen => SOMAXCONN, Reuse => 1); die "can't setup server" unless $server; print "[Servidor $0 esperando conexoes]\n"; while ($client = $server->accept()) { $client->autoflush(2); print $client "Seja Bem Vindo $0; type help for command .\n"; $hostinfo = gethostbyaddr($client->peeraddr); printf "[Conexao vindo de %s]\n", $hostinfo->name || $client->peerhost; die "can't fork: $!" unless defined($kidpid = fork()); if ($kidpid) { # copy standard input to the socket while (defined ($line = )) { # aqui envia para o cliente print $client $line; } } else { while (defined ($line = <$client>)) { print STDOUT "Cliente diz: $line\n"; # print STDOUT $line; } kill("TERM", $kidpid); # send SIGTERM to child } close $client; }