ID EN
Socket

create_connection

Python 3.11

Connect to a TCP service listening on the internet address (a 2-tuple (host, port)), and return the socket object. This is a higher-level function than socket.connect(): if host is a non-numeric hostname, it will try to resolve it for both AF_INET and AF_INET6, and then try to connect to all possible addresses in turn until a connection succeeds. This makes it easy to write clients that are compatible to both IPv4 and IPv6.

Syntax

PYTHON
socket.create_connection(address, timeout=GLOBAL_DEFAULT, source_address=None, *, all_errors=False)

See Also

socket.connect() AF_INET AF_INET6 getdefaulttimeout() ExceptionGroup