mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
fix #27211: clarify how to use UDP server sockets
#please review this git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@164812 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
496f28b233
commit
90e6fc874c
3 changed files with 28 additions and 13 deletions
|
@ -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>
|
||||
|
|
|
@ -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>,
|
||||
|
|
|
@ -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 @@ if (!$socket) {
|
|||
<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>
|
||||
|
|
Loading…
Reference in a new issue