#!/usr/bin/perl use strict; use IO::Socket::INET; my ($port,$hostname,$protocol) = (2000,'localhost','tcp'); my $handle = IO::Socket::INET->new( Proto => $protocol, PeerAddr => $hostname, PeerPort => $port ) || die "Cannot connect to host [$hostname] on port [$port]: $!"; while (defined(my $line = <$handle>)) { chomp $line; print "Received from [$hostname:$port]: $line\n"; } $handle->close();