Chapter 20. Sockets and Server-Side Network Protocol Modules

To communicate with the Internet, programs use objects known as sockets. The Python library supports sockets through module socket, as well as wrapping them into higher-level client-side modules, as covered in Chapter 19. To help you write server programs, the Python library also supplies higher-level modules to use as frameworks for socket servers. Standard and third-party Python modules and extensions also support asynchronous socket operations. This chapter covers socket, in The socket Module; server-side framework modules, in The SocketServer Module; asynchronous operation with standard Python library modules, in Event-Driven Socket Programs; and the bare essentials of the rich and powerful Twisted third-party package, in The Twisted Framework.

The modules covered in this chapter offer many conveniences compared to C-level socket programming. However, in the end, the modules rely on native socket functionality supplied by the underlying operating system. While it is often possible to write effective network clients by using just the modules covered in Chapter 19 without really needing to understand sockets, writing effective network servers most often does require some understanding of sockets. Thus, the lower-level module socket is covered in this chapter and not in Chapter 19, even though both clients and servers use sockets.

However, I cover only the ways in which module socket lets your program access sockets; I ...

Get Python in a Nutshell, 2nd Edition 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.