Advertisement
MRC

socket.pl

MRC
Jul 27th, 2012
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.41 KB | None | 0 0
  1. #! /usr/bin/perl
  2.  
  3. use IO::Socket::INET;
  4. use strict;
  5.  
  6. my $server_socket = IO::Socket::INET->new(
  7. 'LocalPort' => '2008',
  8. 'Proto' => 'tcp',
  9. 'Reuse' => 1,
  10. 'Listen' => SOMAXCONN
  11. ) or die "Não foi possível criar o socket. ($!)\n";
  12.  
  13. print "Servidor iniciado.\n";
  14.  
  15. while (my $cliente = $server_socket->accept){
  16. while (<$cliente>) {
  17. print "Mensagem recebida: $_";
  18. print $cliente "Mensagem enviada: $_ ";
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement