leonidlm has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I wrote the following UDP "pooler" code:
sub sampleNode { my ($msg, $peerAddr, $eTime) = @_; my $bol = 0; print "Sending the message to the server for node $msg...\n"; $MySocket = new IO::Socket::INET->new( PeerPort => 6060, Proto => 'udp', PeerAddr => $peerAddr, ); ioctl($MySocket, 0x8004667e, pack("I", 1)); $MySocket->send($msg); while((time() < $eTime) && (!$bol)) { #print "time: " . time() . ", threshold: $eTime\n"; $MySocket->recv($text,128); print $text; if($text =~ /OK/) { print "Received ok response: $text"; $bol = 1; } } return $bol; }
My question is very simple: What the following line does? ioctl($MySocket, 0x8004667e, pack("I", 1)); Whotout this line the timeout just won't work, it freezes on $MySocket->recv($text,128); I just found it and paste it in my code and now it is working! I really want to fully understand that. Thanks all!

Replies are listed 'Best First'.
Re: UDP socket connect.
by glide (Pilgrim) on Jan 31, 2008 at 11:28 UTC
      Thx. Can you explain in more detail about this command? 1. each parameter 2. Why I can't use something from the Sockets module? If I remember right there is a blocking parameter in the New method. 3. Why for Windows? Thx, and sorry for the bulk of quastions :)
        1
      • for the ioctl follow the link
      • for the code, 0x8004667e, see in Re^2: Non-blocking socket read on Windows
      • apparently the ioctl expect a reference as a parameter. Probably you can replace the pack by
        my $nonblocking = 1; ioctl($self, 0x8004667e, \$nonblocking);

        2 Yes, the option (Blocking) is in the IO::Socket::INET. Try it, and remove the ioctl line.

        3 Aren't you using windows? :-)
        When working with sockets, you can't entirely ignore the platform, some time you have to adapt the code (options) to the platform.

Re: UDP socket connect.
by glide (Pilgrim) on Jan 31, 2008 at 11:12 UTC
    Hi,

    It's very difficult to read your question. Please, read the Writeup Formatting Tips, and update the post.

    update: thanks