tornado.tcpclient
— IOStream
connection factory¶
A non-blocking TCP connection factory.
-
class
tornado.tcpclient.
TCPClient
(resolver: Optional[tornado.netutil.Resolver] = None)[source]¶ A non-blocking TCP connection factory.
Changed in version 5.0: The
io_loop
argument (deprecated since version 4.1) has been removed.-
coroutine
connect
(host: str, port: int, af: socket.AddressFamily = <AddressFamily.AF_UNSPEC: 0>, ssl_options: Union[Dict[str, Any], ssl.SSLContext, None] = None, max_buffer_size: Optional[int] = None, source_ip: Optional[str] = None, source_port: Optional[int] = None, timeout: Union[float, datetime.timedelta, None] = None) → tornado.iostream.IOStream[source]¶ Connect to the given host and port.
Asynchronously returns an
IOStream
(orSSLIOStream
ifssl_options
is not None).Using the
source_ip
kwarg, 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
TimeoutError
if the input future does not complete beforetimeout
, which may be specified in any form allowed byIOLoop.add_timeout
(i.e. adatetime.timedelta
or an absolute time relative toIOLoop.time
)Similarly, when the user requires a certain source port, it can be specified using the
source_port
arg.Changed in version 4.5: Added the
source_ip
andsource_port
arguments.Changed in version 5.0: Added the
timeout
argument.
-
coroutine