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 utilized 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.