#! perl.exe -w ######################################################################################## ## ## Client_Skeleton ## ######################################################################################## use strict; use Getopt::Long qw (GetOptions); use IO::Socket; #List of variables used in this program my (%opts, $VERSION,); $VERSION = "1.0"; #Set the options for GetOpt Getopt::Long::Configure( "pass_through", "no_ignore_case", "prefix_pattern=(-|\/)" ); #What to expect on the command line %opts = (); GetOptions (\%opts, 'help|h|?', 'port=s', 'server=s', 'msg=s', ); #Set help option on if the correct parameters are not inserted $opts{help} = 1 unless (defined $opts{port} && defined $opts{server} && defined $opts{msg}); if( $opts{help} ) { Syntax(); exit(); } &Transmit_Msg($opts{msg}); ######################################################################################## ## ## SUB ROUTINES ## ######################################################################################## #Create socket connection and send message to server. sub Transmit_Msg($msg) { my $MAXLEN = 1024; my $msg = shift; my $sock = IO::Socket::INET->new( Proto => 'tcp', PeerPort => $opts{port}, PeerAddr => $opts{server}, ) or die "Could Not Connect to Server Socket(Check Service is Running): $!\n"; print $sock "$msg\n"; # &Notify("Sent $msg"); close ($sock); } #Print out the proper syntax if some parameters are missing. sub Syntax { my( $Script ) = ( $0 =~ m#([^\\/]+)$# ); my $Scriptdetails = "$Script - Version: $VERSION"; my $Line = "-" x length( $Scriptdetails ); print << "EOT"; $Scriptdetails $Line This program will send a TCP message to the server. You Must add Port and Server Address as well as the Message to send in Quotes Syntax: $0 [-p|--port=] [-s|--server=] [-m|--msg=<"Message To Send"[-h|--help|?] EOT }