Jump to content

Archived

This topic is now archived and is closed to further replies.

Lorian

socket_recvfrom timeout?

Recommended Posts

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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.