#!/usr/bin/perl -w -s ################### # client1 - stripped down clientDemo ################### use strict; use IO::Socket; our $host = 'localhost' unless $host; our $port = 3003 unless $port; # must match server's our $pause= 0 unless $pause; # delay after connect print STDOUT "CLIENT: starting clientDemo. \n"; my $sock = IO::Socket::INET->new( Proto => 'tcp', PeerAddr => $host, PeerPort => $port, ) or die "CLIENT: Failed to connect (host='$host',port='$port'); $@"; print STDOUT "CLIENT: connected \n"; $sock->autoflush(1); # make sure we're sending stuff right out $sock->blocking(1); # make sure we wait (block) for other end on reads my $message = "Hello. Client time is " . scalar localtime(); print STDOUT "CLIENT: sending '$message' \n"; $sock->print($message."\n"); # write a line to the server chomp(my $response = $sock->getline); # read a line from the server print STDOUT "CLIENT: received '$response'\n"; print STDOUT "CLIENT: closing connection.\n"; close($sock); exit;