Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
It establishes the connection to the remote server just fine, and even sends the query data, but it hangs in the while loop after "Retrieving Result...", which leads me to believe I'm doing this incorrectly. When I connect to a host, it should be able to reply to me on the same socket I connected with, right?use strict; use warnings; use Carp; use IO::Socket; use Smart::Comments; # hostname and port of server to query my $hostname = '88.191.48.146:27888'; ### Creating socket... my $sock = new IO::Socket::INET( PeerAddr => $hostname, LocalAddr => 'localhost', Proto => 'udp', ) or croak "can't bind: $@\n"; # die unless socket is verifiably connected if(! defined $sock->connected) { croak 'socket failed to connect'; } # build query string my $query_string = sprintf "\xFE\xFD\x00%s\xFF\xFF\xFF", 'RTFM'; ### Sending query string... $sock->print($query_string); ### Retrieving result... my $response; while(<$sock>) { $response .= $_; } ### Closing socket... $sock->close; ### We're done here, exit... exit;
Did I misunderstand some vital piece? Are sockets even the way to go? I would really appreciate any help or advice, thanks so much!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sending a low-level query using sockets? (A confused newbie)
by Fletch (Bishop) on Mar 01, 2007 at 15:48 UTC | |
|
Re: Sending a low-level query using sockets? (A confused newbie)
by EvanK (Chaplain) on Mar 01, 2007 at 15:55 UTC | |
by Ojosh!ro (Beadle) on Mar 01, 2007 at 16:24 UTC | |
|
Re: Sending a low-level query using sockets? (A confused newbie)
by Thelonius (Priest) on Mar 01, 2007 at 22:15 UTC |