liveBook · Manning

Connection socket

As explained in Python Concurrency with asyncio

A connection socket is a socket endpoint representing an established communication channel with a client.

A connection socket is the server-side endpoint created for one client after accept returns. Unlike the listening server socket, it carries communication with that client: data can be read from it and written to it. section 3.1

A blocking server obtains a connection socket in this sequence:

  • Create, bind, and start listening on the server socket. section 3.1
  • Call accept; it waits until a client connects, then returns the connection socket and client address. section 3.1
  • Use the returned socket to communicate with that client. section 3.1

Accepting one client

connection, client_address = server_socket.accept()\nprint(f'I got a connection from {client_address}!') section 3.1

Figure 3.1 A client connects to our server socket. The server then creates a new socket to communicate with the client.
03-01

Shows the listening server socket creating a separate socket for communication with the connected client. section 3.1

How Python Concurrency with asyncio covers it

How deep it goes
Defines the returned socket and its relationship to listening, but does not detail subsequent read and write operations.
Examples
Uses a TCP server at 127.0.0.1:8000 and telnet to demonstrate a client connection.
What you can do after
Build it from scratch as a blocking TCP server that accepts one connection and reports its client address.
How it connects
Connects server sockets, accept, client addresses, blocking sockets, and TCP communication.

Related concepts

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.