Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a30d82f

Browse files
committed
Document create_connection
1 parent 9a62a19 commit a30d82f

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

Doc/library/asyncio.rst

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,71 @@ a different clock than :func:`time.time`.
115115

116116
This method's behavior is the same as :meth:`call_later`.
117117

118+
Creating connections
119+
^^^^^^^^^^^^^^^^^^^^
120+
121+
.. method:: create_connection(protocol_factory, host=None, port=None, **options)
122+
123+
Create a streaming transport connection to a given Internet *host* and
124+
*port*. *protocol_factory* must be a callable returning a
125+
:ref:`protocol <protocol>` instance.
126+
127+
This method returns a :ref:`coroutine <coroutine>` which will try to
128+
establish the connection in the background. When successful, the
129+
coroutine returns a ``(transport, protocol)`` pair.
130+
131+
The chronological synopsis of the underlying operation is as follows:
132+
133+
#. The connection is established, and a :ref:`transport <transport>`
134+
is created to represent it.
135+
136+
#. *protocol_factory* is called without arguments and must return a
137+
:ref:`protocol <protocol>` instance.
138+
139+
#. The protocol instance is tied to the transport, and its
140+
:meth:`connection_made` method is called.
141+
142+
#. The coroutine returns successfully with the ``(transport, protocol)``
143+
pair.
144+
145+
The created transport is an implementation-dependent bidirectional stream.
146+
147+
.. note::
148+
*protocol_factory* can be any kind of callable, not necessarily
149+
a class. For example, if you want to use a pre-created
150+
protocol instance, you can pass ``lambda: my_protocol``.
151+
152+
*options* are optional named arguments allowing to change how the
153+
connection is created:
154+
155+
* *ssl*: if given and not false, a SSL/TLS transport is created
156+
(by default a plain TCP transport is created). If *ssl* is
157+
a :class:`ssl.SSLContext` object, this context is used to create
158+
the transport; if *ssl* is :const:`True`, a context with some
159+
unspecified default settings is used.
160+
161+
* *server_hostname*, is only for use together with *ssl*,
162+
and sets or overrides the hostname that the target server's certificate
163+
will be matched against. By default the value of the *host* argument
164+
is used. If *host* is empty, there is no default and you must pass a
165+
value for *server_hostname*. If *server_hostname* is an empty
166+
string, hostname matching is disabled (which is a serious security
167+
risk, allowing for man-in-the-middle-attacks).
168+
169+
* *family*, *proto*, *flags* are the optional address family, protocol
170+
and flags to be passed through to getaddrinfo() for *host* resolution.
171+
If given, these should all be integers from the corresponding
172+
:mod:`socket` module constants.
173+
174+
* *sock*, if given, should be an existing, already connected
175+
:class:`socket.socket` object to be used by the transport.
176+
If *sock* is given, none of *host*, *port*, *family*, *proto*, *flags*
177+
and *local_addr* should be specified.
178+
179+
* *local_addr*, if given, is a ``(local_host, local_port)`` tuple used
180+
to bind the socket to locally. The *local_host* and *local_port*
181+
are looked up using getaddrinfo(), similarly to *host* and *port*.
182+
118183

119184
.. _protocol:
120185

@@ -470,6 +535,12 @@ Methods of subprocess transports
470535
On Windows, this method is an alias for :meth:`terminate`.
471536

472537

538+
.. _coroutine:
539+
540+
Coroutines
541+
----------
542+
543+
473544
.. _sync:
474545

475546
Synchronization primitives

0 commit comments

Comments
 (0)