--FILE--
<?php
/* Setup socket server */
- $server = stream_socket_server('udp://127.0.0.1:31338', $errno, $errstr, STREAM_SERVER_BIND);
+ for ($port = 31338; $port < 31500; ++$port) {
+ $uri = "udp://127.0.0.1:$port";
+ $server = @stream_socket_server($uri, $errno, $errstr, STREAM_SERVER_BIND);
+ if ($server) break;
+ }
if (!$server) {
- die('Unable to create AF_INET socket [server]');
+ die('Unable to create AF_INET socket [server]: ' . $errstr);
}
/* Connect to it */
- $client = stream_socket_client('udp://127.0.0.1:31338');
+ $client = stream_socket_client($uri);
if (!$client) {
die('Unable to create AF_INET socket [client]');
}