An asyncio-based chat server

The asyncio Standard Library module is new in Python 3.4 and it is an effort at bringing some standardization around asynchronous I/O into the Standard Library. The asyncio library uses a co-routine based style of programming. It provides a powerful loop class, which our programs can submit prepared tasks, called co-routines, to, for asynchronous execution. The event loop handles the scheduling of the tasks and optimization of performance around blocking I/O calls.

It has built-in support for socket-based networking, which makes building a basic server a straightforward task. Let's see how this can be done. Create a new file called 5.1-chat_server-asyncio.py and save the following code in it:

import asyncio import tincanchat ...

Get Learning Python Network Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.