8 Streams

 

This chapter covers

  • Transports and protocols
  • Using streams for network connections
  • Processing command-line input asynchronously
  • Creating client/server applications with streams

When writing network applications, such as our echo clients in prior chapters, we’ve employed the socket library to read from and write to our clients. While directly using sockets is useful when building low-level networking libraries, they are ultimately complex creatures with nuances outside the scope of this book. That said, many use cases of sockets rely on a few conceptually simple operations, such as starting a server, waiting for client connections, and sending data to clients. The designers of asyncio realized this and built network stream APIs to abstract away handling the nuances of sockets for us. These higher-level APIs are much easier to work with than sockets, making any client-server applications easier to build and more robust than using sockets ourselves. Using streams is the recommended way to build network-based applications in asyncio.

8.1 Introducing streams

8.2 Transports and protocols

8.3 Stream readers and stream writers

8.4 Non-blocking command-line input

8.4.1 Terminal raw mode and the read coroutine

8.5 Creating servers

8.6 Creating a chat server and client

Summary

sitemap