Open Internet or Unix domain socket connection with UDP in PHP

Description

The following code shows how to open Internet or Unix domain socket connection with UDP.

Example


//from www.j a  v a  2 s .  c  om

//retrieve the day and time from the 
//UDP service "daytime" (port 13) in your own machine.
<?php
$fp = fsockopen("udp://127.0.0.1", 13, $errno, $errstr);
if (!$fp) {
    echo "ERROR: $errno - $errstr<br />\n";
} else {
    fwrite($fp, "\n");
    echo fread($fp, 26);
    fclose($fp);
}
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Development »




Environment
Error
Hash
Include
Locale
Math
Network
Output
Reflection
PHP Regular Expressions