Section 16.6. Related Modules


16.6. Related Modules

Table 16.4 lists some of the other Python modules that 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.4. Network/Socket Programming Related Modules

Module

Description

socket

Lower-level networking interface as discussed in this chapter

asyncore/asynchat

Provide infrastructure to create networked applications that process clients asynchronously

select

Manages multiple socket connections in a single-threaded network server application

SocketServer

High-level module that provides server classes for networked applications, complete with forking or threading varieties


The async* and SocketServer modules both provide higher-level functionality as far as creating servers is 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.

Although async* provide the only asynchronous development support in the standard library, we have seen a third-party package that is much more contemporary and powerful than those older modules, Twisted. Although the example code we have seen in this chapter is slightly longer than the barebones scripts, Twisted provides a much more powerful and flexible framework and has implemented many protocols for you already. You can find out more about Twisted at its Web site:

http://twistedmatrix.com

The topics 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 20.



Core Python Programming
Core Python Programming (2nd Edition)
ISBN: 0132269937
EAN: 2147483647
Year: 2004
Pages: 334
Authors: Wesley J Chun

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net