Thanks Javafan. Using IO::Select is a good idea.

#!/usr/bin/perl -w # # udp client which sends a query, waits for timeout # seconds and prints response if obtained else cribs. # use strict; use IO::Socket; use IO::Select; my $srvhost = '10.1.1.111'; my $srvport = '3333'; my $client = new IO::Socket::INET( PeerAddr => $srvhost, PeerPort => $srvport, Proto => 'udp'); my $sel = new IO::Select($client); my @ready; my $sock; my $request = "e8aa9e somequery 123"; my $maxread = 1024; while (1) { if (! defined($client->send($request))) { die "failed to send req\n"; } print "sent $request\n\n"; @ready = $sel->can_read(5); if (! scalar(@ready)) { print "Response Timed out\n"; } else { $sock = $ready[0]; if (! sysread($ready[0], $response, $maxread)) { print "recv failed :$!\n"; } else { print "got response $response\n"; } } sleep 3; }

I don't need to do recv as I can read through sysread, and this being a server response I don't need to send back any replies - so I don't need recv for its capabilities of getting the remote host's information. I don't even need to be in blocking mode now - or do I?. Am I right in saying this?


In reply to Re^2: how to set socket recv timeout in architecture independent manner? by saurabh.hirani
in thread how to set socket recv timeout in architecture independent manner? by saurabh.hirani

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.