#!/usr/local/bin/perl8 use 5.006001; use strict; use warnings; use IO::Socket; my $sock = undef; eval { while (1) { outsend(scalar(localtime()) . "\n"); sleep 5; } }; if (my $e = $@) { die "Exception: $e"; } sub outsend { my $data = shift; $sock ||= IO::Socket::INET->new( PeerAddr => '127.0.0.1', PeerPort => 5555, Proto => 'tcp', ) || die $!; my $lw = syswrite($sock, $data); die $! unless defined $lw and $lw == length($data); }