Dearest Monks, I've been googling all morning and can't quite get the following to work as needed. I have a server that I am successfully connecting to with IO::Socket::INET. I need to connect to this server every 5 minutes and make sure that I am getting a particular string from it when I send it a particular command. The response to the command could take up to 5 minutes. Again, the connecting to the server and the sending of the command part is working fine. I'm stuck at how to monitor the server after sending the command for 5 minutes and waiting to see if it responds with the particular string. It needs to timeout after five minutes with an error if the string isn't received. Here is the code so far. All it is currently doing is connecting to the server and printing out any output received.
#!/usr/bin/perl use IO::Socket::INET; $host = shift; $port = shift; $MySocket = new IO::Socket::INET->new("$host:$port") or die "connect: +$@"; $command = "EDMSFT\|ISL\|\@\n"; $MySocket->send($command); while (1) { $MySocket->recv($text,128); print "$text\n"; } close $MySocket;

In reply to Using IO::Socket by Earindil

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.