1
0
mirror of https://github.com/php/doc-ru.git synced 2026-03-26 00:32:15 +01:00
Files
archived-doc-ru/reference/sockets/functions/socket-bind.xml
Sergey Panteleev 6d43fd64d7 Исправление форматирования
[skip-spellcheck]
[skip-lint]
2022-12-27 03:42:36 +03:00

184 lines
6.0 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 14dc7c47365f2b71f6c907a5ba5bccf42534d5a9 Maintainer: countzero Status: ready -->
<!-- Reviewed: no -->
<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>
Экземпляр <classname>Socket</classname>, созданный при помощи функции <function>socket_create</function>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>address</parameter></term>
<listitem>
<para>
Если сокет из семейства <constant>AF_INET</constant>, то параметр
<parameter>address</parameter> должен быть IP-адресом в записи,
разделённой точками (например, <literal>127.0.0.1</literal>).
</para>
<para>
Если сокет из семейства <constant>AF_UNIX</constant>, то параметр
<parameter>address</parameter> - это путь к
доменному сокету Unix (например, <filename>/tmp/my.sock</filename>).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>port</parameter> (Optional)</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>
<note>
<para>
Примечание по совместимости с Windows 9x/ME:
Функция <function>socket_last_error</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
-->