CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
IO::Socket::INET timeout?

 



Rivotti
User

Feb 3, 2003, 10:23 AM

Post #1 of 2 (913 views)
IO::Socket::INET timeout? Can't Post

I have this script that connect to a game server using UDP.

while (1) {
$Sock = IO::Socket::INET->new(
PeerAddr => $address,
Proto => 'udp'
) or die;
$Sock->autoflush(1);

$Sock->send(
$command
);

if (defined($Sock->recv($response, 4096))) {
print $response;
}
sleep 40
}

Ok, it works but, if the address is wrong, or disconnected, the script won't stop. He will stay there for ever. How to die if the server doesn't exist?

Thanks in advance
Rivotti
André Rivotti Casimiro
Web Designer/Programmer
MyGamesPlayer.com
http://www.mygamesplayer.com


jryan
User

Feb 6, 2003, 10:48 PM

Post #2 of 2 (905 views)
Re: [Rivotti] IO::Socket::INET timeout? [In reply to] Can't Post


In Reply To
Ok, it works but, if the address is wrong, or disconnected, the script won't stop. He will stay there for ever. How to die if the server doesn't exist?


Thats what the 'else' clause of the if statement is for :)


Code
if (defined $Sock->recv($response, 4096)) { 
print $response;
}
else {
die "Error recieving data: $!\n";
}


However, if you need reliable responses, I wonder why you are using UDP over TCP/IP in the first place...

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives