2 error_reporting(E_ALL | E_STRICT);
5 define('MAX_FAILURES', 3);
7 require("udp-inc.php");
11 function validate ($data) {
28 out(__FUNCTION__, __LINE__, "Unknown hasher: ${hasher}");
38 $client = stream_socket_client("udp://192.168.1.1:1113", $errno, $errstr);
40 if ((!is_resource($client)) || ($errno > 0)) {
41 echo "ERROR: $errno - $errstr\n";
45 if (!stream_set_blocking($client, 0)) {
46 echo "ERROR: Cannot set non-blocking mode!\n";
50 out(__FILE__, __LINE__, "Starting test...");
51 while (!feof($client)) {
52 //out(__FILE__, __LINE__, "Sending ping...");
53 fwrite($client, "PING");
55 //out(__FILE__, __LINE__, "Reading reply...");
56 $read = trim(fread($client, 50));
59 out(__FILE__, __LINE__, "Empty line received. Is the server there?");
60 } elseif ($read == "INVALID") {
62 out(__FILE__, __LINE__, "Server has not accepted our message.");
65 //out(__FILE__, __LINE__, "Response ${read} received.");
68 if ($failed == constant('MAX_FAILURES')) {
69 out(__FILE__, __LINE__, "Too many failures! (failed=${failed})");
71 } elseif ($failed < constant('MAX_FAILURES')) {
75 $rec = explode(":", $read);
78 $right = explode("=", $rec[1]);
82 if (validate($time) != $hash) {
83 out(__FILE__, __LINE__, "Invalid: ${read}/{$hash}");
88 if (!isset($data[$rec[0]])) {
89 if (count($data) > 0) {
90 echo $data[$rec[0]-1]."\n";
92 if ($cnt > constant('ROUNDS')) break;
101 stream_socket_shutdown($client, STREAM_SHUT_RDWR);
107 foreach ($data as $cnt) {
111 if (($cnt < $min) || ($min == 0)) {
117 if (count($data) > 0) {
118 $avg = round($avg / count($data));
121 out(__FILE__, __LINE__, "MIN/AVG/MAX=${min}/${avg}/${max}");
122 out(__FILE__, __LINE__, "INVALID=${invalid}");