Related Modules
Table 16.3 lists some of the other Python modules which are related to network and socket programming. The select module is usually used in conjunction with the socket module when developing lower-level socket applications. It provides the select() function which manages sets of socket objects. One of the most useful things it does is to take a set of sockets and listen for active connections on them. The select() function will block until at least one socket is ready for communication, and when that happens, it provides you with a set of which ones are ready for reading. (It can also determine which are ready for writing, although that is not as common as the former operation.)
Table 16.3. Network/Socket Programming Related Modules
Module |
Description |
asyncore |
provides infrastructure to create networked applications which process clients asynchronously |
select |
manages multiple socket connections in a single-threaded network server application |
SocketServer |
high-level module which provides server classes for networked applications, complete with forking or threading varieties |
The asyncore and SocketServer modules both provide higher-level functionality as far as create servers are concerned. Written on top of the socket and/or select modules, they enable more rapid development of client-server systems because all the lower-level code is handled for you. All you have to do is to create or subclass the appropriate base classes, and you are on your way. As we mentioned earlier, SocketServer even provides the capability of integrating threading or new processes into the server for more parallelized processing of client requests.
The topics which we have covered in this chapter deal with network programming with sockets in Python and how to create custom applications using lower-level protocol suites such as TCP/IP and UDP/IP. If you want to develop higher-level Web and Internet applications, we strongly encourage you to head to Chapter 19.