Created
July 27, 2011 12:24
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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