s.bind(addr) Bind the socket to an address. This causes the socket to listen on a network port. Sockets on the other side of this connection will use ``Socket.connect(addr)`` to connect to this socket. Returns a context manager which will call unbind on exi
(self: _SocketType, addr: str)
| 289 | return _SocketContext(self, 'bind', addr) |
| 290 | |
| 291 | def bind(self: _SocketType, addr: str) -> _SocketContext[_SocketType]: |
| 292 | """s.bind(addr) |
| 293 | |
| 294 | Bind the socket to an address. |
| 295 | |
| 296 | This causes the socket to listen on a network port. Sockets on the |
| 297 | other side of this connection will use ``Socket.connect(addr)`` to |
| 298 | connect to this socket. |
| 299 | |
| 300 | Returns a context manager which will call unbind on exit. |
| 301 | |
| 302 | .. versionadded:: 20.0 |
| 303 | Can be used as a context manager. |
| 304 | |
| 305 | .. versionadded:: 26.0 |
| 306 | binding to port 0 can be used as a context manager |
| 307 | for binding to a random port. |
| 308 | The URL can be retrieved as `socket.last_endpoint`. |
| 309 | |
| 310 | Parameters |
| 311 | ---------- |
| 312 | addr : str |
| 313 | The address string. This has the form 'protocol://interface:port', |
| 314 | for example 'tcp://127.0.0.1:5555'. Protocols supported include |
| 315 | tcp, udp, pgm, epgm, inproc and ipc. If the address is unicode, it is |
| 316 | encoded to utf-8 first. |
| 317 | |
| 318 | """ |
| 319 | try: |
| 320 | super().bind(addr) |
| 321 | except ZMQError as e: |
| 322 | e.strerror += f" (addr={addr!r})" |
| 323 | raise |
| 324 | return self._bind_cm(addr) |
| 325 | |
| 326 | def connect(self: _SocketType, addr: str) -> _SocketContext[_SocketType]: |
| 327 | """s.connect(addr) |