programming-examples/perl/Network/TCP server.pl
2019-11-15 12:59:38 +01:00

23 lines
542 B
Perl

#!/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";
}