#!/usr/bin/perl use IO::Socket::INET; # auto-flush on socket $| = 1; # create a connecting socket my $socket = new IO::Socket::INET ( PeerHost => 'localhost', PeerPort => '25', Proto => 'tcp', ); die "cannot connect to the server $!\n" unless $socket; print "connected to the server\n"; # data to send to a server my $name = `hostname`; my $req = "helo $name\n"; my $size = $socket->send($req); # notify server that request has been sent shutdown($socket, 1); # receive a response of up to 1024 characters from server my $response = ""; $socket->recv($response, 1024); print "received response: $response\n"; $socket->close();