From a1ef6ebcd65af5fb8ef9d280da78a7c309c51f80 Mon Sep 17 00:00:00 2001 From: "Jesus M. Castagnetto" Date: Tue, 8 Aug 2000 08:31:42 +0000 Subject: [PATCH] Added info on UDP support and a simple example that connects to the datetime service git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@29871 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/network.xml | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/functions/network.xml b/functions/network.xml index 434fb7250f..c8922c9f80 100644 --- a/functions/network.xml +++ b/functions/network.xml @@ -119,7 +119,9 @@ int fsockopen - string hostname + + string udp://hostname + int port int errno @@ -133,14 +135,17 @@ - Initiates a stream connection in the Internet (AF_INET) or Unix - (AF_UNIX) domain. For the Internet domain, it will open a TCP - socket connection to hostname on port - port. For the Unix domain, - hostname will be used as the path to the - socket, port must be set to 0 in this - case. The optional timeout can be used to - set a timeout in seconds for the connect system call. + Initiates a stream connection in the Internet (AF_INET, using + TCP or UDP) or Unix (AF_UNIX) domain. For the Internet domain, + it will open a TCP + socket connection to hostname on + port port. For UDP connections, you need + to explicitely specify the the protocol: + udp://hostname. For the Unix domain, + hostname will be used as the path to the + socket, port must be set to 0 in this + case. The optional timeout can be used + to set a timeout in seconds for the connect system call. Fsockopen returns a file pointer which may @@ -185,6 +190,23 @@ if (!$fp) { } + The example below shows how to retrieve the day and time + from the UDP service "daytime" (port 13) in your own machine. + + Using UDP connection + +<?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); +} +?> + + See also: pfsockopen