Book Image

Python Network Programming

By : Abhishek Ratan, Eric Chou, Pradeeban Kathiravelu, Dr. M. O. Faruque Sarker
Book Image

Python Network Programming

By: Abhishek Ratan, Eric Chou, Pradeeban Kathiravelu, Dr. M. O. Faruque Sarker

Overview of this book

This Learning Path highlights major aspects of Python network programming such as writing simple networking clients, creating and deploying SDN and NFV systems, and extending your network with Mininet. You’ll also learn how to automate legacy and the latest network devices. As you progress through the chapters, you’ll use Python for DevOps and open source tools to test, secure, and analyze your network. Toward the end, you'll develop client-side applications, such as web API clients, email clients, SSH, and FTP, using socket programming. By the end of this Learning Path, you will have learned how to analyze a network's security vulnerabilities using advanced network packet capture and analysis techniques. This Learning Path includes content from the following Packt products: • Practical Network Automation by Abhishek Ratan • Mastering Python Networking by Eric Chou • Python Network Programming Cookbook, Second Edition by Pradeeban Kathiravelu, Dr. M. O. Faruque Sarker
Table of Contents (30 chapters)
Title Page
Copyright
About Packt
Contributors
Preface
Index

Using ForkingMixIn in your socket server applications


You have decided to write an asynchronous Python socket server application. The server will not block in processing a client request. So the server needs a mechanism to deal with each client independently.

Python SocketServer class comes with two utility classes: ForkingMixIn and ThreadingMixIn. The ForkingMixIn class will spawn a new process for each client request. This class is discussed in this section. The ThreadingMixIn class will be discussed in the next section. For more information, you can refer to the relevant Python 2 documentation at http://docs.python.org/2/library/socketserver.htmland Python 3 documentation athttps://docs.python.org/3/library/socketserver.html.

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