O'Reilly logo

Learning Python Network Programming by Sam Washington, Dr. M. O. Faruque Sarker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required