mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 05:26:57 +08:00
270 lines
9.3 KiB
HTML
270 lines
9.3 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||
<html>
|
||
<head>
|
||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||
<title>创建一个套接字(通讯节点)</title>
|
||
</head>
|
||
<body class="docs"><div id="layout">
|
||
<div id="layout-content"><div id="function.socket-create" class="refentry">
|
||
<div class="refnamediv">
|
||
<h1 class="refname">socket_create</h1>
|
||
<p class="verinfo">(PHP 4 >= 4.1.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">socket_create</span> — <span class="dc-title">创建一个套接字(通讯节点)</span></p>
|
||
|
||
</div>
|
||
|
||
<div class="refsect1 description" id="refsect1-function.socket-create-description">
|
||
<h3 class="title">说明</h3>
|
||
<div class="methodsynopsis dc-description">
|
||
<span class="methodname"><strong>socket_create</strong></span>
|
||
( <span class="methodparam"><span class="type">int</span> <code class="parameter">$domain</code></span>
|
||
, <span class="methodparam"><span class="type">int</span> <code class="parameter">$type</code></span>
|
||
, <span class="methodparam"><span class="type">int</span> <code class="parameter">$protocol</code></span>
|
||
) : <span class="type">resource</span></div>
|
||
|
||
<p class="para rdfs-comment">
|
||
创建并返回一个套接字,也称作一个通讯节点。一个典型的网络连接由 2 个套接字构成,一个运行在客户端,另一个运行在服务器端。
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 parameters" id="refsect1-function.socket-create-parameters">
|
||
<h3 class="title">参数</h3>
|
||
<p class="para">
|
||
<dl>
|
||
|
||
|
||
<dt>
|
||
<code class="parameter">domain</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">
|
||
<code class="parameter">domain</code> 参数指定哪个协议用在当前套接字上。
|
||
</p>
|
||
<table class="doctable table">
|
||
<caption><strong>可用的地址/协议</strong></caption>
|
||
|
||
<thead>
|
||
<tr>
|
||
<th>Domain</th>
|
||
<th>描述</th>
|
||
</tr>
|
||
|
||
</thead>
|
||
|
||
<tbody class="tbody">
|
||
<tr>
|
||
<td><strong><code>AF_INET</code></strong></td>
|
||
<td>
|
||
IPv4 网络协议。TCP 和 UDP 都可使用此协议。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td><strong><code>AF_INET6</code></strong></td>
|
||
<td>
|
||
IPv6 网络协议。TCP 和 UDP 都可使用此协议。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td><strong><code>AF_UNIX</code></strong></td>
|
||
<td>
|
||
本地通讯协议。具有高性能和低成本的 IPC(进程间通讯)。
|
||
</td>
|
||
</tr>
|
||
|
||
</tbody>
|
||
|
||
</table>
|
||
|
||
</dd>
|
||
|
||
|
||
|
||
<dt>
|
||
<code class="parameter">type</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">
|
||
<code class="parameter">type</code> 参数用于选择套接字使用的类型。
|
||
</p>
|
||
<table class="doctable table">
|
||
<caption><strong>可用的套接字类型</strong></caption>
|
||
|
||
<thead>
|
||
<tr>
|
||
<th>类型</th>
|
||
<th>描述</th>
|
||
</tr>
|
||
|
||
</thead>
|
||
|
||
<tbody class="tbody">
|
||
<tr>
|
||
<td><strong><code>SOCK_STREAM</code></strong></td>
|
||
<td>
|
||
提供一个顺序化的、可靠的、全双工的、基于连接的字节流。支持数据传送流量控制机制。TCP 协议即基于这种流式套接字。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td><strong><code>SOCK_DGRAM</code></strong></td>
|
||
<td>
|
||
提供数据报文的支持。(无连接,不可靠、固定最大长度).UDP协议即基于这种数据报文套接字。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td><strong><code>SOCK_SEQPACKET</code></strong></td>
|
||
<td>
|
||
提供一个顺序化的、可靠的、全双工的、面向连接的、固定最大长度的数据通信;数据端通过接收每一个数据段来读取整个数据包。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td><strong><code>SOCK_RAW</code></strong></td>
|
||
<td>
|
||
提供读取原始的网络协议。这种特殊的套接字可用于手工构建任意类型的协议。一般使用这个套接字来实现 ICMP 请求(例如 ping)。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td><strong><code>SOCK_RDM</code></strong></td>
|
||
<td>
|
||
提供一个可靠的数据层,但不保证到达顺序。一般的操作系统都未实现此功能。
|
||
</td>
|
||
</tr>
|
||
|
||
</tbody>
|
||
|
||
</table>
|
||
|
||
</dd>
|
||
|
||
|
||
|
||
<dt>
|
||
<code class="parameter">protocol</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">
|
||
<code class="parameter">protocol</code> 参数,是设置指定 <code class="parameter">domain</code>
|
||
套接字下的具体协议。这个值可以使用 <span class="function"><a href="getprotobyname.html" class="function">getprotobyname()</a></span>
|
||
函数进行读取。如果所需的协议是 TCP 或 UDP,可以直接使用常量 <strong><code>SOL_TCP</code></strong> 和 <strong><code>SOL_UDP</code></strong> 。
|
||
</p>
|
||
<table class="doctable table">
|
||
<caption><strong>常见协议</strong></caption>
|
||
|
||
<thead>
|
||
<tr>
|
||
<th>名称</th>
|
||
<th>描述</th>
|
||
</tr>
|
||
|
||
</thead>
|
||
|
||
<tbody class="tbody">
|
||
<tr>
|
||
<td>icmp</td>
|
||
<td>
|
||
Internet Control Message Protocol
|
||
主要用于网关和主机报告错误的数据通信。例如“ping”命令(在目前大部分的操作系统中)就是使用 ICMP 协议实现的。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td>udp</td>
|
||
<td>
|
||
User Datagram Protocol 是一个无连接的、不可靠的、具有固定最大长度的报文协议。由于这些特性,UDP 协议拥有最小的协议开销。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td>tcp</td>
|
||
<td>
|
||
Transmission Control Protocol 是一个可靠的、基于连接的、面向数据流的全双工协议。TCP
|
||
能够保障所有的数据包是按照其发送顺序而接收的。如果任意数据包在通讯时丢失,TCP
|
||
将自动重发数据包直到目标主机应答已接收。因为可靠性和性能的原因,TCP 在数据传输层使用 8bit 字节边界。因此,TCP 应用程序必须允许传送部分报文的可能。
|
||
</td>
|
||
</tr>
|
||
|
||
</tbody>
|
||
|
||
</table>
|
||
|
||
</dd>
|
||
|
||
|
||
</dl>
|
||
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 returnvalues" id="refsect1-function.socket-create-returnvalues">
|
||
<h3 class="title">返回值</h3>
|
||
<p class="para">
|
||
<span class="function"><strong>socket_create()</strong></span> 正确时返回一个套接字,失败时返回
|
||
<strong><code>FALSE</code></strong>。要读取错误代码,可以调用 <span class="function"><a href="socket_last_error.html" class="function">socket_last_error()</a></span>。这个错误代码可以通过 <span class="function"><a href="socket_strerror.html" class="function">socket_strerror()</a></span> 读取文字的错误说明。
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 changelog" id="refsect1-function.socket-create-changelog">
|
||
<h3 class="title">更新日志</h3>
|
||
<p class="para">
|
||
<table class="doctable informaltable">
|
||
|
||
<thead>
|
||
<tr>
|
||
<th>版本</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
|
||
</thead>
|
||
|
||
<tbody class="tbody">
|
||
<tr>
|
||
<td>5.0.0</td>
|
||
<td>
|
||
增加 <strong><code>AF_INET6</code></strong> 支持。
|
||
</td>
|
||
</tr>
|
||
|
||
</tbody>
|
||
|
||
</table>
|
||
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 errors" id="refsect1-function.socket-create-errors">
|
||
<h3 class="title">错误/异常</h3>
|
||
<p class="para">
|
||
如果使用一个无效的 <code class="parameter">domain</code> 或 <code class="parameter">type</code>,<span class="function"><strong>socket_create()</strong></span>
|
||
会使用 <strong><code>AF_INET</code></strong> 和
|
||
<strong><code>SOCK_STREAM</code></strong> 替代无效参数,同时会发出 <strong><code>E_WARNING</code></strong> 警告信息。
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 seealso" id="refsect1-function.socket-create-seealso">
|
||
<h3 class="title">参见</h3>
|
||
<p class="para">
|
||
<ul class="simplelist">
|
||
<li class="member"><span class="function"><a href="socket_accept.html" class="function" rel="rdfs-seeAlso">socket_accept()</a> - Accepts a connection on a socket</span></li>
|
||
<li class="member"><span class="function"><a href="socket_bind.html" class="function" rel="rdfs-seeAlso">socket_bind()</a> - 给套接字绑定名字</span></li>
|
||
<li class="member"><span class="function"><a href="socket_connect.html" class="function" rel="rdfs-seeAlso">socket_connect()</a> - 开启一个套接字连接</span></li>
|
||
<li class="member"><span class="function"><a href="socket_listen.html" class="function" rel="rdfs-seeAlso">socket_listen()</a> - Listens for a connection on a socket</span></li>
|
||
<li class="member"><span class="function"><a href="socket_last_error.html" class="function" rel="rdfs-seeAlso">socket_last_error()</a> - Returns the last error on the socket</span></li>
|
||
<li class="member"><span class="function"><a href="socket_strerror.html" class="function" rel="rdfs-seeAlso">socket_strerror()</a> - Return a string describing a socket error</span></li>
|
||
</ul>
|
||
</p>
|
||
</div>
|
||
|
||
|
||
</div></div></div></body></html> |