Python Network Programming
by Abhishek Ratan, Eric Chou, Pradeeban Kathiravelu, Dr. M. O. Faruque Sarker
How to do it...
Let us rewrite our echo server, previously described in Chapter 11, Sockets, IPv4, and Simple Client/Server Programming. We can utilize the subclasses of the SocketServer class family. It has ready-made TCP, UDP, and other protocol servers. We can create a ForkingServer class inherited from TCPServer and ForkingMixIn. The former parent will enable our ForkingServer class to do all the necessary server operations that we did manually before, such as creating a socket, binding to an address, and listening for incoming connections. Our server also needs to inherit from ForkingMixIn to handle clients asynchronously.
The ForkingServer class also needs to set up a request handler that dictates how to handle a client request. Here ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access