svn: /phpdoc/en/trunk/reference/sockets/functions/ socket-recv.xml

From: Date: Mon, 14 Sep 2009 20:02:17 +0000
Subject: svn: /phpdoc/en/trunk/reference/sockets/functions/ socket-recv.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-4924@lists.php.net to get a copy of this message
torben Mon, 14 Sep 2009 20:02:17 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=288342 Log: Cleaned up the example. Folded in a little information from the user notes. Changed paths: U phpdoc/en/trunk/reference/sockets/functions/socket-recv.xml Modified: phpdoc/en/trunk/reference/sockets/functions/socket-recv.xml =================================================================== --- phpdoc/en/trunk/reference/sockets/functions/socket-recv.xml 2009-09-14 19:27:47 UTC (rev 288341) +++ phpdoc/en/trunk/reference/sockets/functions/socket-recv.xml 2009-09-14 20:02:17 UTC (rev 288342) @@ -50,7 +50,9 @@ <listitem> <para> The data received will be fetched to the variable specified with - <parameter>buf</parameter>. + <parameter>buf</parameter>. If an error occurs, if the + connection is reset, or if no data is + available, <parameter>buf</parameter> will be set to &null;. </para> </listitem> </varlistentry> @@ -157,8 +159,7 @@ /* Create a TCP/IP socket. */ $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($socket === false) { - echo "socket_create() failed: reason: " -. socket_strerror(socket_last_error()) . "\n"; + echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n"; } else { echo "OK.\n"; } @@ -166,8 +167,7 @@ echo "Attempting to connect to '$address' on port '$service_port'..."; $result = socket_connect($socket, $address, $service_port); if ($result === false) { - echo "socket_connect() failed.\nReason: ($result) " -. socket_strerror(socket_last_error($socket)) . "\n"; + echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n"; } else { echo "OK.\n"; } @@ -182,12 +182,15 @@ echo "OK.\n"; echo "Reading response:\n\n"; -$buf = ''; -socket_recv($socket, $buf, 2048, MSG_WAITALL); -echo "Closing socket..."; +$buf = 'This is my buffer.'; +if (false !== ($bytes = socket_recv($socket, $buf, 2048, MSG_WAITALL))) { + echo "Read $bytes bytes from socket_recv(). Closing socket..."; +} else { + echo "socket_recv() failed; reason: " . socket_strerror(socket_last_error($socket)) . "\n"; +} socket_close($socket); -echo $buf; +echo $buf . "\n"; echo "OK.\n\n"; ?> ]]>

« previous php.doc.cvs (#4924) next »