October 2018
Beginner to intermediate
466 pages
12h 2m
English
The sort service example should look familiar by now, as it has a similar boilerplate to other AsyncIO programs. However, there are a few differences. We called start_server instead of create_server. This method hooks into AsyncIO's streams instead of using the underlying transport/protocol code. It allows us to pass in a normal coroutine, which receives reader and writer parameters. These both represent streams of bytes that can be read from and written, like files or sockets. Second, because this is a TCP server instead of UDP, there is some socket cleanup required when the program finishes. This cleanup is a blocking call, so we have to run the wait_closed coroutine on the event loop.
Streams are fairly simple to understand. Reading ...