Lorian Posted April 17, 2006 Share Posted April 17, 2006 I have got a script that sends a message to a server and waits for a response, but I can't find any way to make it timeout after say 2 seconds. Here is (the relevant bit of) my code:[code]function query ($ip, $port = 29900) { $buf = chr (254).chr (253).chr (0).chr (4).chr (5).chr (6).chr (7).chr (255). chr (255).chr (255).chr (1); $socket = socket_create (AF_INET, SOCK_DGRAM, SOL_UDP); socket_set_option ($socket, SOL_SOCKET, SO_BROADCAST, 1); socket_sendto ($socket, $buf, strlen ($buf), 0, $ip, $port); $packet = null; if (!socket_recvfrom ($socket, $packet, 2048, 0, $ip, $port)) { $players = -1; } else { $players = parse ($packet); } return $players;}[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.