Chapter 10. Twisted networking

 

This chapter covers

  • Writing networked programs in Python
  • Designing multiplayer games (including testing them on your friends)
  • Issues you’ll encounter when writing asynchronous programs

In this chapter, we’ll be revisiting the adventure game you wrote in chapter 6 and extending it so you can log in and play it with other people via the internet. Normally these games are referred to as MUDs, which stands for Multi-User Dungeon. Depending on the person creating them, MUDs can range from fantasy hack-and-slash to science fiction, and players can compete or cooperate to earn treasure, points, or fame.

To get you started quickly, we’ll use a framework called Twisted, which contains libraries for working with many different networking protocols and servers.

Installing Twisted

The first step is to install Twisted and get a test application running. Twisted comes with installers for Windows and Macintosh, which are available from the Twisted homepage at http://twistedmatrix.com/. Some versions of MacOS ship with Twisted already installed, in which case it’s easier to use that version. If you’re using Linux, there should be packages available through your package manager.

The installer will pop up a window as it compiles things, but once you see the window on the right in figure 10.1, Twisted is installed!

Figure 10.1. Installing Twisted on Windows

Your first application

First steps with your MUD

Making the game more fun

Making your life easier

Making your world permanent

Where to from here?

Summary