MCPcopy Create free account
hub / github.com/EasyIME/PIME / TCPClient

Class TCPClient

python/python3/tornado/tcpclient.py:198–328  ·  view source on GitHub ↗

A non-blocking TCP connection factory. .. versionchanged:: 5.0 The ``io_loop`` argument (deprecated since version 4.1) has been removed.

Source from the content-addressed store, hash-verified

196
197
198class TCPClient(object):
199 """A non-blocking TCP connection factory.
200
201 .. versionchanged:: 5.0
202 The ``io_loop`` argument (deprecated since version 4.1) has been removed.
203 """
204
205 def __init__(self, resolver: Optional[Resolver] = None) -> None:
206 if resolver is not None:
207 self.resolver = resolver
208 self._own_resolver = False
209 else:
210 self.resolver = Resolver()
211 self._own_resolver = True
212
213 def close(self) -> None:
214 if self._own_resolver:
215 self.resolver.close()
216
217 async def connect(
218 self,
219 host: str,
220 port: int,
221 af: socket.AddressFamily = socket.AF_UNSPEC,
222 ssl_options: Optional[Union[Dict[str, Any], ssl.SSLContext]] = None,
223 max_buffer_size: Optional[int] = None,
224 source_ip: Optional[str] = None,
225 source_port: Optional[int] = None,
226 timeout: Optional[Union[float, datetime.timedelta]] = None,
227 ) -> IOStream:
228 """Connect to the given host and port.
229
230 Asynchronously returns an `.IOStream` (or `.SSLIOStream` if
231 ``ssl_options`` is not None).
232
233 Using the ``source_ip`` kwarg, one can specify the source
234 IP address to use when establishing the connection.
235 In case the user needs to resolve and
236 use a specific interface, it has to be handled outside
237 of Tornado as this depends very much on the platform.
238
239 Raises `TimeoutError` if the input future does not complete before
240 ``timeout``, which may be specified in any form allowed by
241 `.IOLoop.add_timeout` (i.e. a `datetime.timedelta` or an absolute time
242 relative to `.IOLoop.time`)
243
244 Similarly, when the user requires a certain source port, it can
245 be specified using the ``source_port`` arg.
246
247 .. versionchanged:: 4.5
248 Added the ``source_ip`` and ``source_port`` arguments.
249
250 .. versionchanged:: 5.0
251 Added the ``timeout`` argument.
252 """
253 if timeout is not None:
254 if isinstance(timeout, numbers.Real):
255 timeout = IOLoop.current().time() + timeout

Callers 4

initializeMethod · 0.90
__init__Method · 0.90
setUpMethod · 0.90
test_connect_timeoutMethod · 0.90

Calls

no outgoing calls

Tested by 2

setUpMethod · 0.72
test_connect_timeoutMethod · 0.72