Hey Guys,

Ok so I got this working...

So I use this Perl Script along with another one that runs in the background on a remote terminal server.
This script will now establish a socket connection with the remote server, send an initial "acceptance" message
so the remote server knows it is a valid connection. If the remote server does not receive the valid string it
will close the connection.

Now I guess I'm at a good point where I can now use this as a base program and build off of it...
Thanks again for your help guys... Guess it woulda been bad if I used the dead "LWP::Socket" module. So thanks for
letting me know!

Here's my Code:
#!/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 conve +rts it to an ACTUAL IP Address (*not a string)... my $iaddr = inet_aton($remote) or die "Unable to resolve hostname: $re +mote... $!\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, "<getTickerData/>", 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;


Thanks again for the thoughts and suggestions, very much appreciated!


If anyone finds themselves trying to do something similar to this I found a few really good sites that helped me through this:

   DOCUMENTATION:
      http://search.cpan.org/~dapm/perl-5.14.4/ext/Socket/Socket.pm
   REALLY GOOD EXAMPLES HERE:
      http://www.binarytides.com/perl-socket-programming-tutorial/
      http://www.herongyang.com/Perl/Socket-connect-Establish-Socket-Communication.html


Thanks Again,
Matt


In reply to Re: Error while using LWP::Socket to send XML Data by mmartin
in thread Error while using LWP::Socket to send XML Data by mmartin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.