<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.sockets.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.socket-getpeername.php',
    1 => 'socket_getpeername',
    2 => '获取套接字远端名字',
  ),
  'up' => 
  array (
    0 => 'ref.sockets.php',
    1 => 'Socket 函数',
  ),
  'prev' => 
  array (
    0 => 'function.socket-getopt.php',
    1 => 'socket_getopt',
  ),
  'next' => 
  array (
    0 => 'function.socket-getsockname.php',
    1 => 'socket_getsockname',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/sockets/functions/socket-getpeername.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.socket-getpeername" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">socket_getpeername</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.1.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">socket_getpeername</span> &mdash; <span class="dc-title">获取套接字远端名字</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.socket-getpeername-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>socket_getpeername</strong></span>(<span class="methodparam"><span class="type"><a href="class.socket.php" class="type Socket">Socket</a></span> <code class="parameter">$socket</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter reference">&$address</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter reference">&$port</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   获取套接字远端名字，返回主机名和端口号或是 Unix 文件系统路径，具体取决于套接字类型。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.socket-getpeername-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">socket</code></dt>
     <dd>
      <p class="para">
       由 <span class="function"><a href="function.socket-create.php" class="function">socket_create()</a></span> 或 <span class="function"><a href="function.socket-accept.php" class="function">socket_accept()</a></span> 创建的 <span class="classname"><a href="class.socket.php" class="classname">Socket</a></span> 实例。
      </p>
     </dd>
    
    
     <dt><code class="parameter">address</code></dt>
     <dd>
      <p class="para">
       如果给定套接字的类型是 <strong><code><a href="sockets.constants.php#constant.af-inet">AF_INET</a></code></strong> 
       或 <strong><code><a href="sockets.constants.php#constant.af-inet6">AF_INET6</a></code></strong>，<span class="function"><strong>socket_getpeername()</strong></span> 
       将在参数 <code class="parameter">address</code> 上返回对端（远端） <em>IP 地址</em> 
       （例如：<code class="literal">127.0.0.1</code> 或 <code class="literal">fe80::1</code>），如果存在端口号，也将关联到 <code class="parameter">port</code> 参数。
      </p>
      <p class="para">
       如果给定套接字的类型是 <strong><code><a href="sockets.constants.php#constant.af-unix">AF_UNIX</a></code></strong>，<span class="function"><strong>socket_getpeername()</strong></span> 
       将在 <code class="parameter">address</code> 参数中返回 Unix 文件系统路径（例如：<code class="literal">/var/run/daemon.sock</code>）。
      </p>
     </dd>
    
    
     <dt><code class="parameter">port</code></dt>
     <dd>
      <p class="para">
       如果提供此参数，它将保存 <code class="parameter">address</code> 关联的端口号。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.socket-getpeername-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>， 或者在失败时返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>。 如果套接字类型不是 <strong><code><a href="sockets.constants.php#constant.af-inet">AF_INET</a></code></strong>、<strong><code><a href="sockets.constants.php#constant.af-inet6">AF_INET6</a></code></strong> 
   或 <strong><code><a href="sockets.constants.php#constant.af-unix">AF_UNIX</a></code></strong> 中的任意一个，<span class="function"><strong>socket_getpeername()</strong></span> 
   也可能返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>，在此情况下，套接字最后的错误码<em>不会</em>更新。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.socket-getpeername-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
  <td>8.0.0</td>
  <td>
   现在 <code class="parameter">socket</code> 是 <span class="classname"><a href="class.socket.php" class="classname">Socket</a></span> 实例，
   之前是 <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span>。
  </td>
 </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 notes" id="refsect1-function.socket-getpeername-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    <span class="function"><strong>socket_getpeername()</strong></span> 不应该用于 <span class="function"><a href="function.socket-accept.php" class="function">socket_accept()</a></span> 
    创建的 <strong><code><a href="sockets.constants.php#constant.af-unix">AF_UNIX</a></code></strong> 类型套接字。只有使用 <span class="function"><a href="function.socket-connect.php" class="function">socket_connect()</a></span> 
    创建的套接字或调用过 <span class="function"><a href="function.socket-bind.php" class="function">socket_bind()</a></span> 的服务端套接字会返回有意义的值。
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    为了让 <span class="function"><strong>socket_getpeername()</strong></span> 返回有意义的值，套接字使用 “peer“ 的概念是有意义的（the socket it is applied upon must of course be one for which the concept of &quot;peer&quot; makes sense）。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.socket-getpeername-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.socket-getsockname.php" class="function" rel="rdfs-seeAlso">socket_getsockname()</a> - 获取套接字本地端的名字，返回主机名和端口号或是 Unix 文件系统路径，具体取决于套接字类型</span></li>
    <li><span class="function"><a href="function.socket-last-error.php" class="function" rel="rdfs-seeAlso">socket_last_error()</a> - 返回套接字上的最后一个错误</span></li>
    <li><span class="function"><a href="function.socket-strerror.php" class="function" rel="rdfs-seeAlso">socket_strerror()</a> - 返回描述套接字错误的字符串</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>