#!/usr/bin/perl -Tw # martin-client # # assembled and modified by Tkil 2001-02-07 # originally lifted in bits from "perlipc" documentation. # # released under the same terms as the sample code in the perl # documentation, as that is where this code had its start. require 5.002; use strict; use Socket; use Carp; # set up the socket from the client (us) to the server. # create the socket. my $proto = getprotobyname 'tcp'; socket SERVER, PF_INET, SOCK_STREAM, $proto or die "socket: $!"; # bind the socket to port 2345 on any interface. my $serv_host = "localhost"; my $serv_port = 2345; my $serv_paddr = sockaddr_in($serv_port, inet_aton($serv_host)); connect SERVER, $serv_paddr or die "connect: $!"; # make the SERVER filehandle unbuffered. my $orig_fh = select SERVER; $| = 1; select $orig_fh; # now we can treat it mostly like a normal filehandle. while(defined($_ = )) { print "<-- $_"; # display every line we recieve. # is this something we should reply to? my $msg = ""; if (/^Please send \"hello\" next\./) { $msg = "hello"; } elsif (/^Ok, now send me a number\./) { $msg = "1000000"; } # do we have anything to say? if ($msg ne '') { print SERVER $msg, "\n"; # send it to the server print "--> $msg\n"; # and display it. } } # done with conversation. exit 0;