#!/usr/bin/perl -l use POSIX qw(SIGALRM); sub Begin { eval { use strict; use warnings; POSIX::sigaction(SIGALRM, POSIX::SigAction->new(sub { die; })) || die "Error setting SIGALRM handler: $!"; alarm 3; }; } use strict; use warnings; use sigtrap; use IO::Socket; $|=1; my ($socket, $client); my $host = '192.168.1.255'; my $port = '5500'; my $listen = 10; $socket = IO::Socket::INET->new( LocalHost => $host, LocalPort => $port, Proto => 'tcp', Listen => $listen, ReuseAddr => 1, Blocking => 1, Timeout => 3, ) or die "Couldn't create socket: $!"; print "Waiting for a connection..."; while ($client = $socket->accept()) { my $message = <$socket>; $client->autoflush(1); print $message; close $client; } $socket->close();