mirror of
https://github.com/php/doc-ja.git
synced 2026-03-24 07:02:08 +01:00
178 lines
5.1 KiB
XML
178 lines
5.1 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 35883800e764cccacf5772330bc007b6b08ffc6e Maintainer: hirokawa Status: ready -->
|
|
<!-- CREDITS: takagi -->
|
|
<refentry xml:id="function.socket-bind" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>socket_bind</refname>
|
|
<refpurpose>ソケットに名前をバインドする</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>bool</type><methodname>socket_bind</methodname>
|
|
<methodparam><type>Socket</type><parameter>socket</parameter></methodparam>
|
|
<methodparam><type>string</type><parameter>address</parameter></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>port</parameter><initializer>0</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<parameter>address</parameter> で指定した名前を
|
|
<parameter>socket</parameter> で指定したソケットにバインドします。
|
|
これは、<function>socket_connect</function> あるいは
|
|
<function>socket_listen</function> を使用して接続が確立される前に行われます。
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>socket</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
<function>socket_create</function> で作成した
|
|
<classname>Socket</classname> クラスのインスタンス。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>address</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
ソケットの種類が <constant>AF_INET</constant> の場合、
|
|
<parameter>address</parameter> はドットで 4 つに区切られた表記
|
|
(例: <literal>127.0.0.1</literal>)の IP アドレス。
|
|
</para>
|
|
<para>
|
|
ソケットの種類が <constant>AF_UNIX</constant> の場合、
|
|
<parameter>address</parameter> は Unix ドメインソケット
|
|
(例: <filename>/tmp/my.sock</filename>)。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>port</parameter>(オプション)</term>
|
|
<listitem>
|
|
<para>
|
|
パラメータ <parameter>port</parameter> は
|
|
<constant>AF_INET</constant> ソケットにバインドする場合にのみ使用され、
|
|
接続するリモートホストのポートを指定します。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
&return.success;
|
|
</para>
|
|
<para>
|
|
エラーコードは <function>socket_last_error</function> により取得できます。
|
|
このコードを <function>socket_strerror</function> に渡すことにより、
|
|
エラー内容を表すテキストを得ることができます。
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
&sockets.changelog.socket-param;
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title><function>socket_bind</function> を使用してソースアドレスを指定する</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// 新しいソケットを作成する
|
|
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
|
|
|
// コンピュータが所有する IP アドレスリストの例
|
|
$sourceips['kevin'] = '127.0.0.1';
|
|
$sourceips['madcoder'] = '127.0.0.2';
|
|
|
|
// ソースアドレスをバインドする
|
|
socket_bind($sock, $sourceips['madcoder']);
|
|
|
|
// 接続先アドレスと接続する
|
|
socket_connect($sock, '127.0.0.1', 80);
|
|
|
|
// 書き込む
|
|
$request = 'GET / HTTP/1.1' . "\r\n" .
|
|
'Host: example.com' . "\r\n\r\n";
|
|
socket_write($sock, $request);
|
|
|
|
// 閉じる
|
|
socket_close($sock);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
<note>
|
|
<para>
|
|
この関数は、
|
|
<function>socket_connect</function> の前に実行されている必要があります。
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>socket_connect</function></member>
|
|
<member><function>socket_listen</function></member>
|
|
<member><function>socket_create</function></member>
|
|
<member><function>socket_last_error</function></member>
|
|
<member><function>socket_strerror</function></member>
|
|
</simplelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|