In the previous chapter, we looked at exchanging data between devices by using the sockets interface. In this chapter, we're going to use sockets to build network applications. Sockets follow one of the main models of computer networking, that is, the client/server model. We'll look at this with a focus on structuring server applications. We'll cover the following topics:
Designing a simple protocol
Building an echo server and client
Building a chat server and client
Multithreaded and event-driven server architectures
The
eventlet
andasyncio
libraries
The examples in this chapter are best run on Linux or a Unix operating system. The Windows sockets implementation has some idiosyncrasies, and these can create some error conditions, which we will not be covering here. Note that Windows does not support the poll
interface that we'll use in one example. If you do use Windows, then you'll probably need to use ctrl + break to kill these processes in the console...