#!/usr/bin/perl -w use strict; use IO::Socket::INET; my $server = IO::Socket::INET->new( LocalHost => 'localhost', LocalPort => 12345, Proto => 'tcp', Listen => SOMAXCONN, Reuse => 1 ) or die $!; print "server started\n"; $SIG{PIPE} = 'IGNORE'; while (1) { my $client = $server->accept(); print "accepted connection\n"; $client->autoflush(1); LOOP: for (1..1000) { my $count = int(rand 3)+1; # 1..3 32-bit BE uints, preceded by the respective count my $data = pack "N"x($count+1), $count, ($_)x$count; for (split //, $data) { last LOOP unless print $client $_; select undef, undef, undef, 0.01; # emulate slow delivery } } close $client; }