Skip to content

Instantly share code, notes, and snippets.

@Arthurmourao
Created July 27, 2011 12:24
Show Gist options
  • Save Arthurmourao/1109247 to your computer and use it in GitHub Desktop.
Save Arthurmourao/1109247 to your computer and use it in GitHub Desktop.
Server que recebe pacotes de um client e os imprime na tela. Falta terminar a implementação de um arquivo de log. Made by VI
#! /usr/bin/perl
use IO::Socket::INET;
print "Server ON";
$server = IO::Socket::INET->new(
LocalAddr=>"localhost", # host
LocalPort=> "8081", # porta que vai ficar em listening
Proto=>'tcp', # protocolo
Listen=>10 # numero maximo de clientes conectados
) || die $!;
$sock_client = $server->accept(); # aceitando o socket cliente
while($server)
{
$sock_client->recv($data,8192); # recebendo os dados do cliente
if(@data)
{
print "\nRecebido: $data";
}
else{
break;
}
open (FILE, ">", "LogServer.txt") || die $!;
push (@data, $+{FILE});
#insere os dados recebidos no log
print FILE %data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment