> Hey Nuno, > > A couple of comments: > > The LISTEN flag is used to actually "switch-on" a > connection-orientated transport (eg: TCP) so that it can accept > connections. > > So that sentence should read something like: > > "Connection-orientated transports (such as TCP) must use this flag, > otherwise the server socket will not be enabled. Using this flag for > connect-less transports (such as UDP) is an error."
OK, I'll change that. > PHP 5.1 will include a new function "stream_socket_listen" that will > allow you manually listen(). The rationale for that is that you might > want to alter some socket settings before actually accepting > connections. Currently, there aren't any of these to configure, so it > is low priority. Was this already added? > Rather than saying "this function doesn't work with UDP sockets", you > should say "it is an error to use this function with UDP sockets", > because the function itself isn't broken or deficient; using it with > UDP sockets is an error in your code. I'll change this too. And maybe turn <note> into <warning>. > The UDP example reads only a single byte; check the specs for the > daytime protocol to see how much it should read; if it isn't reading > enough, that script might break. Quote (http://www.faqs.org/rfcs/rfc867.html): "UDP Based Daytime Service Another daytime service service is defined as a datagram based application on UDP. A server listens for UDP datagrams on UDP port 13. When a datagram is received, an answering datagram is sent containing the current date and time as a ASCII character string (the data in the received datagram is ignored)." Uhm, I think 1 byte is enough? Thanks for your comments! Nuno > On Sat, 31 Jul 2004 11:48:38 -0000, Nuno Lopes <[EMAIL PROTECTED]> wrote: > > nlopess Sat Jul 31 07:48:38 2004 EDT > > > > Modified files: > > /phpdoc/en/reference/stream constants.xml > > /phpdoc/en/reference/stream/functions stream-socket-accept.xml > > stream-socket-server.xml > > Log: > > fix #27211: clarify how to use UDP server sockets > > #please review this > > > > http://cvs.php.net/diff.php/phpdoc/en/reference/stream/constants.xml?r1=1.10&r2=1.11&ty=u > > Index: phpdoc/en/reference/stream/constants.xml > > diff -u phpdoc/en/reference/stream/constants.xml:1.10 phpdoc/en/reference/stream/constants.xml:1.11 > > --- phpdoc/en/reference/stream/constants.xml:1.10 Fri May 21 11:20:48 2004 > > +++ phpdoc/en/reference/stream/constants.xml Sat Jul 31 07:48:38 2004 > > @@ -1,5 +1,5 @@ > > <?xml version="1.0" encoding="iso-8859-1"?> > > -<!-- $Revision: 1.10 $ --> > > +<!-- $Revision: 1.11 $ --> > > <section id="stream.constants"> > > &reftitle.constants; > > &extension.constants; > > @@ -95,7 +95,7 @@ > > <entry><constant>STREAM_SERVER_LISTEN</constant> *</entry> > > <entry>Tells a stream created with <function>stream_socket_server</function> > > and bound using the <constant>STREAM_SERVER_BIND</constant> flag to start > > - listening on the socket. Server sockets should always include this flag. > > + listening on the socket. TCP Server sockets should always include this flag. > > </entry> > > </row> > > <row> > > http://cvs.php.net/diff.php/phpdoc/en/reference/stream/functions/stream-socket-accept.xml?r1=1.2&r2=1.3&ty=u > > Index: phpdoc/en/reference/stream/functions/stream-socket-accept.xml > > diff -u phpdoc/en/reference/stream/functions/stream-socket-accept.xml:1.2 phpdoc/en/reference/stream/functions/stream-socket-accept.xml:1.3 > > --- phpdoc/en/reference/stream/functions/stream-socket-accept.xml:1.2 Thu Apr 1 01:31:14 2004 > > +++ phpdoc/en/reference/stream/functions/stream-socket-accept.xml Sat Jul 31 07:48:38 2004 > > @@ -1,5 +1,5 @@ > > <?xml version="1.0" encoding="iso-8859-1"?> > > -<!-- $Revision: 1.2 $ --> > > +<!-- $Revision: 1.3 $ --> > > <refentry id="function.stream-socket-accept"> > > <refnamediv> > > <refname>stream_socket_accept</refname> > > @@ -31,6 +31,13 @@ > > <simpara> > > If the call fails, it will return &false;. > > </simpara> > > + <note> > > + <para> > > + This function doens't work with UDP server sockets. Use > > + <function>stream_socket_recvfrom</function> and > > + <function>stream_socket_sendto</function> instead. > > + </para> > > + </note> > > <para> > > See also <function>stream_socket_server</function>, > > <function>stream_socket_get_name</function>, > > http://cvs.php.net/diff.php/phpdoc/en/reference/stream/functions/stream-socket-server.xml?r1=1.15&r2=1.16&ty=u > > Index: phpdoc/en/reference/stream/functions/stream-socket-server.xml > > diff -u phpdoc/en/reference/stream/functions/stream-socket-server.xml:1.15 phpdoc/en/reference/stream/functions/stream-socket-server.xml:1.16 > > --- phpdoc/en/reference/stream/functions/stream-socket-server.xml:1.15 Wed Jun 16 09:01:22 2004 > > +++ phpdoc/en/reference/stream/functions/stream-socket-server.xml Sat Jul 31 07:48:38 2004 > > @@ -1,5 +1,5 @@ > > <?xml version="1.0" encoding="iso-8859-1"?> > > -<!-- $Revision: 1.15 $ --> > > +<!-- $Revision: 1.16 $ --> > > <refentry id="function.stream-socket-server"> > > <refnamediv> > > <refname>stream_socket_server</refname> > > @@ -32,6 +32,12 @@ > > combination of socket creation flags. The default value of flags is > > <constant>STREAM_SERVER_BIND</constant> | <constant>STREAM_SERVER_LISTEN</constant>. > > </para> > > + <note> > > + <para> > > + For UDP sockets, you must use <constant>STREAM_SERVER_BIND</constant> as > > + the <parameter>flags</parameter> parameter. > > + </para> > > + </note> > > <para> > > This function only creates a socket, to begin accepting connections > > use <function>stream_socket_accept</function>. > > @@ -59,7 +65,7 @@ > > </para> > > <para> > > <example> > > - <title><function>stream_socket_server</function> Example</title> > > + <title>Using TCP server sockets</title> > > <programlisting role="php"> > > <![CDATA[ > > <?php > > @@ -92,17 +98,19 @@ > > <programlisting role="php"> > > <![CDATA[ > > <?php > > -$socket = stream_socket_server("udp://0.0.0.0:13", $errno, $errstr, STREAM_SERVER_BIND); > > +$socket = stream_socket_server("udp://127.0.0.1:1113", $errno, $errstr, STREAM_SERVER_BIND); > > if (!$socket) { > > - echo "ERROR: $errno - $errstr<br />\n"; > > -} else { > > - while ($conn = stream_socket_accept($socket)) { > > - fwrite($conn, date("D M j H:i:s Y\r\n")); > > - fclose($conn); > > - } > > - fclose($socket); > > + die("$errstr ($errno)"); > > } > > + > > +do { > > + $pkt = stream_socket_recvfrom($socket, 1, 0, $peer); > > + echo "$peer\n"; > > + stream_socket_sendto($socket, date("D M j H:i:s Y\r\n"), 0, $peer); > > +} while ($pkt !== false); > > + > > ?> > > + > > ]]> > > </programlisting> > > </example>