#!/usr/bin/perl -w # client.pl #---------------- use strict; use Socket; ### Set the Protocol we will use to connect to the Remote Server: my $proto = getprotobyname('tcp'); ### Declare my Socket Connection: my($sock); socket($sock, AF_INET, SOCK_STREAM, $proto) or die "$!"; ### Set the Remote Host's IP Address and which port we will connect to: my $remote = "192.168.x.xxx"; my $port = 3009; ### Resolve the remote IPAddr to a actual IP Address: # *'inet_aton' Takes a string representing an IP Address and converts it to an ACTUAL IP Address (*not a string)... my $iaddr = inet_aton($remote) or die "Unable to resolve hostname: $remote... $!\n"; ### Build the Socket Address structure using PORT and IPADDR: my $peerAddress = sockaddr_in($port, $iaddr); # Initiate the Socket Connection or Exit if Failed to Connect: connect($sock, $peerAddress) or die "Connection Failed: $!\n"; print "Connected to $remote Server on port $port\n"; # Send Initial "Accept" String: # *This string MUST be sent first, because the server receiving the data must see # this 1st in order to accept the incoming data from this script... send($sock, "", 0); ### While $line is still equal to the Socket Connection Handle, then... while (my $line = <$sock>) { if ($line =~ "VALID REQUEST RECEIVED") { print "***GOT A VALID RESPONSE***\n"; send($sock, "Send some data for remote server", 0); } } close($sock); exit 0;