tornado.tcpclient — IOStream connection factory
A non-blocking TCP connection factory.
- class tornado.tcpclient.TCPClient(resolver: Resolver | None = None)[source]
A non-blocking TCP connection factory.
Changed in version 5.0: The
io_loopargument (deprecated since version 4.1) has been removed.- async connect(host: str, port: int, af: AddressFamily = AddressFamily.AF_UNSPEC, ssl_options: dict[str, Any] | SSLContext | None = None, max_buffer_size: int | None = None, source_ip: str | None = None, source_port: int | None = None, timeout: float | timedelta | None = None) IOStream[source]
Connect to the given host and port.
Asynchronously returns an
IOStream(orSSLIOStreamifssl_optionsis not None).Using the
source_ipkwarg, one can specify the source IP address to use when establishing the connection. In case the user needs to resolve and use a specific interface, it has to be handled outside of Tornado as this depends very much on the platform.Raises
TimeoutErrorif the input future does not complete beforetimeout, which may be specified in any form allowed byIOLoop.add_timeout(i.e. adatetime.timedeltaor an absolute time relative toIOLoop.time)The message of the
TimeoutErrorindicates which phase of the connection timed out: resolving the hostname, establishing the TCP connection (listing the addresses being tried), or performing the TLS handshake.Similarly, when the user requires a certain source port, it can be specified using the
source_portarg.Changed in version 4.5: Added the
source_ipandsource_portarguments.Changed in version 5.0: Added the
timeoutargument.Changed in version 6.6: Timeout errors now have messages describing which phase of the connection process timed out.