Python: Sockets Programming - Multi-Threaded Server
In a previous article , we built a simple socket server that uses only one thread to service client connections, allowing it to service only one client at a time. New clients were able to connect but could not receive or send data to/from the socket server. In this article, we look at how to create a multi-threaded socket server to serve an unlimited number of clients. We use the same code base as the single threaded server and extend it to create multiple threads. The parent socket sets up a listening socket as before and when new clients connect a new child socket object is created. Unlike the single threaded server, we pass the child socket object to a new thread class which then handles all communication with the client in its own thread. Using a while loop the parent socket then goes back to listen for more connections and creates new threads for new connections passing the reference of the child sockets which are created.The code that executes in it own thread and communica...