programming-examples/perl/Network/Example of a Perl TCP server using Socket module.pl

22 lines
554 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
#!/usr/bin/perl -w
use IO::Socket;
$port = 9999;
$server_socket = IO::Socket::INET->new(
LocalPort => $port,
Listen => SOMAXCONN,
Proto => 'tcp',
Reuse => 1)
or die "Cannot open socket: $!";
print "Server listening on port $port\n";
while ( $client_socket = $server_socket->accept() ) {
$client_host = $client_socket->sockhost();
print $client_socket "Hello from server.\n";
print "Sent message to client on $client_host.\n";
$client_socket->close();
}