TCP server : TCP « Network « Perl






TCP server

    

#!/usr/bin/perl 
use warnings;
use strict;
use IO::Socket;

my $port = 4444;
my $server = new IO::Socket::INET(
    Proto     => 'tcp',
    LocalPort => $port,
    Listen => SOMAXCONN,
);

print "Server running on port $port...\n";
while (my $connection = $server->accept) {
    print "Client connected at ", scalar(localtime), "\n";
    print $connection "You're connected to the server!\n";
    while (<$connection>) {
        print "Client says: $_";
    }
    close $connection;
    print "Client disconnected\n";
}

   
    
    
    
  








Related examples in the same category

1.TCP client
2.TCP client using Socket module.
3.TCP inet server
4.tcp inet client
5.Sample TCP client without the Socket module.
6.Sample TCP client.
7.Simple TCP Clients
8.Example of a Perl TCP server using Socket module.