> For the complete documentation index, see [llms.txt](https://treasuremaster.gitbook.io/python-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://treasuremaster.gitbook.io/python-docs/moduli-standartnoi-biblioteki-1/setevoe-i-mezhprocessnoe-vzaimodeistvie/socket/obekty-soketov/socket.bind.md).

# socket.bind ()

### socket.bind ( *address* )

Привязывает сокет к адресу ***address***. Сокет еще не должен быть привязан. (Формат адреса ***address*** зависит от семейства адресов сокетов - см. [выше](/python-docs/moduli-standartnoi-biblioteki-1/setevoe-i-mezhprocessnoe-vzaimodeistvie/socket/semeistvo-soketov.md).)

Вызывает событие аудита `socket.bind` с аргументами ***self***, ***address***.

### Пример

```python
sockobj.bind((myHost, myPort))
```

{% hint style="success" %}
Связывает объект сокета с адресом - для IP-адресов передается имя компьютера сервера и номер порта на этом компьютере. Здесь сервер идентифицирует компьютер и порт, связанные с сокетом. В серверных программах имя компьютера обычно задается пустой строкой `("")`, что означает компьютер, на котором выполняется сценарий (формально, все локальные и удаленные интерфейсы доступные на компьютере), а порт указывается как число за пределами диапазона `0-1023` (зарезервированного для стандартных протоколов, описывавшихся выше).

Обратите внимание, что у каждой поддерживаемой службы сокетов должен быть свой номер порта. Если попытаться открыть сокет на порту, который уже используется, Python возбудит исключение. Обратите  также внимание на вложенные скобки в этом вызове - здесь для сокета с протоколом [AF\_INET](/python-docs/moduli-standartnoi-biblioteki-1/setevoe-i-mezhprocessnoe-vzaimodeistvie/socket/konstanty-soketov/socket.af_inet.md) мы передаем методу **bind** адрес сокета хост/порт, как объект кортежа из двух элементов (для [AF\_UNIX](/python-docs/moduli-standartnoi-biblioteki-1/setevoe-i-mezhprocessnoe-vzaimodeistvie/socket/konstanty-soketov/socket.af_unix.md) передается строка). Технически метод **bind** принимает кортеж значений, соответствующий типу создаваемого сокета.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://treasuremaster.gitbook.io/python-docs/moduli-standartnoi-biblioteki-1/setevoe-i-mezhprocessnoe-vzaimodeistvie/socket/obekty-soketov/socket.bind.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
