"Fossies" - the Fresh Open Source Software Archive

Member "node-runner-0.6.0/include/query_udp.php" (17 Aug 2004, 1007 Bytes) of package /linux/www/old/node-runner-0.6.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "query_udp.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 // This is an example script that queries a UDP service on a given node.
    4 // Note that this script will only work without modification if you are querying
    5 // something like the "daytime" service that doesn't require anything more than
    6 // a character return as input.
    7 
    8 array_push($queries_type_array, "UDP");
    9 
   10 function udp_query($description, $ipaddress, $port, $ptime) {
   11   global $debug;
   12   
   13   $status = array();
   14 
   15   $socket = fsockopen("udp://$ipaddress", $port, $errno, $errstr, $ptime);
   16   stream_set_timeout($socket, $ptime);
   17   if ($socket) {
   18     fwrite($socket,"\n");
   19     $output = fread($socket, 35);
   20   }
   21 
   22   if ((!$socket) || (!$output)) {
   23     $status[0] = 0;
   24     $status[1] = $description." DOWN";
   25     if ($debug == 1) { $status[1] .= " - UDP Port ".$port." Unreachable."; }
   26   } else {
   27     $status[0] = 1;
   28     $status[1] = $description." UP";
   29     if ($debug == 1) { $status[1] .= " - Daytime: ".$output; }
   30   }
   31   
   32   if ($socket) { fclose($socket); }
   33 
   34   $status[1] .= "\n";
   35   return $status;
   36 
   37 }
   38 
   39 ?>