function.socket-sendto.html
来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 233 行
HTML
233 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Sends a message to a socket, whether it is connected or not</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.socket-send.html">socket_send</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.socket-set-block.html">socket_set_block</a></div> <div class="up"><a href="ref.sockets.html">Socket Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.socket-sendto" class="refentry"> <div class="refnamediv"> <h1 class="refname">socket_sendto</h1> <p class="verinfo">(PHP 4 >= 4.0.7, PHP 5)</p><p class="refpurpose"><span class="refname">socket_sendto</span> — <span class="dc-title">Sends a message to a socket, whether it is connected or not </span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">int</span> <span class="methodname"><b><b>socket_sendto</b></b></span> ( <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$socket</tt></span> , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$buf</tt></span> , <span class="methodparam"><span class="type">int</span> <tt class="parameter">$len</tt></span> , <span class="methodparam"><span class="type">int</span> <tt class="parameter">$flags</tt></span> , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$addr</tt></span> [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$port</tt></span> ] )</div> <p class="para rdfs-comment"> The function <b>socket_sendto()</b> sends <i><tt class="parameter">len</tt></i> bytes from <i><tt class="parameter">buf</tt></i> through the socket <i><tt class="parameter">socket</tt></i> to the <i><tt class="parameter">port</tt></i> at the address <i><tt class="parameter">addr</tt></i>. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">socket</tt></i></span> <dd> <p class="para"> A valid socket ressource created using <a href="function.socket-create.html" class="function">socket_create()</a>. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">buf</tt></i></span> <dd> <p class="para"> The sent data will be taken from buffer <i><tt class="parameter">buf</tt></i>. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">len</tt></i></span> <dd> <p class="para"> <i><tt class="parameter">len</tt></i> bytes from <i><tt class="parameter">buf</tt></i> will be sent. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">flags</tt></i></span> <dd> <p class="para"> The value of <i><tt class="parameter">flags</tt></i> can be any combination of the following flags, joined with the binary OR (<i>|</i>) operator. <table border="5"> <caption><b>Possible values for <i><tt class="parameter">flags</tt></i></b></caption> <colgroup> <tbody valign="middle" class="tbody"> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>MSG_OOB</tt></b></td> <td colspan="1" rowspan="1" align="left"> Send OOB (out-of-band) data. </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>MSG_EOR</tt></b></td> <td colspan="1" rowspan="1" align="left"> Indicate a record mark. The sent data completes the record. </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>MSG_EOF</tt></b></td> <td colspan="1" rowspan="1" align="left"> Close the sender side of the socket and include an appropriate notification of this at the end of the sent data. The sent data completes the transaction. </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>MSG_DONTROUTE</tt></b></td> <td colspan="1" rowspan="1" align="left"> Bypass routing, use direct interface. </td> </tr> </tbody> </colgroup> </table> </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">addr</tt></i></span> <dd> <p class="para"> IP address of the remote host. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">port</tt></i></span> <dd> <p class="para"> <i><tt class="parameter">port</tt></i> is the remote port number at which the data will be sent. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> <b>socket_sendto()</b> returns the number of bytes sent to the remote host or -1 if an error occured. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 <b>socket_sendto()</b> Example</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /> $sock </span><span style="color: #007700">= </span><span style="color: #0000BB">socket_create</span><span style="color: #007700">(</span><span style="color: #0000BB">AF_INET</span><span style="color: #007700">, </span><span style="color: #0000BB">SOCK_DGRAM</span><span style="color: #007700">, </span><span style="color: #0000BB">SOL_UDP</span><span style="color: #007700">);<br /><br /> </span><span style="color: #0000BB">$msg </span><span style="color: #007700">= </span><span style="color: #DD0000">"Ping !"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$len </span><span style="color: #007700">= </span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$msg</span><span style="color: #007700">);<br /><br /> </span><span style="color: #0000BB">socket_sendto</span><span style="color: #007700">(</span><span style="color: #0000BB">$sock</span><span style="color: #007700">, </span><span style="color: #0000BB">$msg</span><span style="color: #007700">, </span><span style="color: #0000BB">$len</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #DD0000">'127.0.0.1'</span><span style="color: #007700">, </span><span style="color: #0000BB">1223</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">socket_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$sock</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.socket-send.html" class="function" rel="rdfs-seeAlso">socket_send()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.socket-send.html">socket_send</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.socket-set-block.html">socket_set_block</a></div> <div class="up"><a href="ref.sockets.html">Socket Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?