2 error_reporting(E_ALL | E_STRICT);
5 define('MAX_FAILURES', 3);
7 require("udp-inc.php");
11 function validate ($data) {
27 print("Unknown hasher: ${hasher}\n");
37 $client = stream_socket_client("udp://192.168.1.1:1113", $errno, $errstr);
39 if ((!is_resource($client)) || ($errno > 0)) {
40 echo "ERROR: $errno - $errstr\n";
44 if (!stream_set_blocking($client, 0)) {
45 echo "ERROR: Cannot set non-blocking mode!\n";
49 out(__FILE__, __LINE__, "Starting test...");
50 while (!feof($client)) {
51 //out(__FILE__, __LINE__, "Sending ping...");
52 fwrite($client, "PING");
54 //out(__FILE__, __LINE__, "Reading reply...");
55 $read = trim(fread($client, 50));
58 out(__FILE__, __LINE__, "Empty line received. Is the server there?");
59 } elseif ($read == "INVALID") {
61 out(__FILE__, __LINE__, "Server has not accepted our message.");
64 //out(__FILE__, __LINE__, "Response ${read} received.");
67 if ($failed == constant('MAX_FAILURES')) {
68 out(__FILE__, __LINE__, "Too many failures! (failed=${failed})");
70 } elseif ($failed < constant('MAX_FAILURES')) {
74 $rec = explode(":", $read);
77 $right = explode("=", $rec[1]);
81 if (validate($time) != $hash) {
82 out(__FILE__, __LINE__, "Invalid: ${read}/{$hash}");
87 if (!isset($data[$rec[0]])) {
88 if (count($data) > 0) {
89 echo $data[$rec[0]-1]."\n";
91 if ($cnt > constant('ROUNDS')) break;
100 stream_socket_shutdown($client, STREAM_SHUT_RDWR);
106 foreach ($data as $cnt) {
110 if (($cnt < $min) || ($min == 0)) {
116 if (count($data) > 0) {
117 $avg = round($avg / count($data));
120 out(__FILE__, __LINE__, "MIN/AVG/MAX=${min}/${avg}/${max}");
121 out(__FILE__, __LINE__, "INVALID=${invalid}");