How to do it...

Let's write a simple web server that can return a single line of text to any connected web browser.

The core idea is during the initialization of this web server, we should make a call to select.epoll() and register our server's file descriptor for event notifications. In the web server's executive code, the socket event is monitored as follows:

Listing 2.4 Simple web server using select.epoll #!/usr/bin/env python # Python Network Programming Cookbook, Second Edition -- Chapter - 2 # This program is optimized for Python 2.7.12 and Python 3.5.2. # It may run on any other version with/without modifications. import socket import select import argparse SERVER_HOST = 'localhost' EOL1 = b'\n\n' EOL2 = b'\n\r\n' SERVER_RESPONSE ...

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