liveBook · Manning

Connection_made

As explained in Python Concurrency with asyncio

connection_made is an asyncio protocol callback invoked after the underlying connection has been established.

connection_made is an asyncio.Protocol callback that a transport invokes after the underlying socket connects successfully. It receives the transport, which the protocol can use to communicate with the server immediately. section 8.2

Use connection_made as the opening step in a transport-and-protocol exchange:

  • Define a class extending asyncio.Protocol. section 8.2
  • Accept the transport and write the HTTP request as soon as the connection is established. section 8.2
  • Handle subsequent bytes in data_received and completion in eof_received. section 8.2

Starting an HTTP GET

HTTPGetClientProtocol.connection_made stores or uses the supplied transport to send a GET / HTTP/1.1 request. loop.create_connection constructs the protocol, while get_response awaits the eventual response.

How Python Concurrency with asyncio covers it

How deep it goes
Defines the callback, its transport argument, and its role before deferring response buffering and shutdown to other callbacks.
Examples
Uses an HTTPGetClientProtocol to send an HTTP GET request through a transport after connecting to an HTTP server.
What you can do after
Apply it via asyncio by sending initial data from a protocol's connection callback.
How it connects
Connects asyncio protocols with transports, sockets, data_received, eof_received, and HTTP requests.

This explainer was generated by Manning's knowledge graph from the text of Python Concurrency with asyncio. The section links point to the parts of the book it draws on.