Where to Go from Here

The design here works for short-lived connections and low traffic. If you want to handle multiple simultaneous requests, there are several different strategies, but they all involve quite a bit of work. One option is to create separate threads to handle each request (look in the thread and threading modules in the Python Library Reference). Another is to use nonblocking sockets and the select statement, which looks at a bunch of sockets and tells you which have data ready to read or are ready to accept outgoing data.[2]

We won’t go any further into building sockets applications here. We’ve gone about as far as we can simply, and it gets more complex from here on.

Fortunately the work has been done for you. The Python standard library module socketserver.py provides an extremely useful generic server architecture. It includes a generic server class that you might or might not need to subclass and a request-handler class you definitely want to override. This is an excellent place to go next. Several other standard library modules define web servers based on the standard socket server.

We hope we have made it clear that sockets programming is not only feasible but also straightforward on Python. It’s comparatively rare to need to develop your own socket-based protocols, and if you do need to do it, you will know far more about the subject than we can cover here.

World-class networking software has been developed in Python; examples include the Infoseek search engine, ...

Get Python Programming On Win32 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.