use strict; use IO::Socket::INET; use IO::Select; my $sock = IO::Socket::INET->new(PeerAddr => "localhost:4455"); print $sock "Pid $$\n"; # the init string, used as a 'name' for this client, you may want something more descriptive/informative etc. my $select = IO::Select->new($sock); my $i = 0; for(;;) { #main loop unless(int(rand(5))) { my $msg = "It has been $i iterations since I last sent something\n"; print "Sending message: $msg"; print $sock $msg; $i=0; } if($select->can_read(0)) { #could capture sockets, but there is only one die "observer gone\n" if $sock->eof(); print "Got a message:\n ".<$sock>; } $i++; sleep 1; }