O'Reilly logo

Python Network Programming Cookbook - Second Edition by Dr. M. O. Faruque Sarker, Pradeeban Kathiravelu

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

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

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