
174 MAKING THINGS TALK
Conclusion
The client should also place a priority on listening, but
it has to juggle listening to the server with listening to
the physical inputs. It should always give a clear and
immediate response to local input, and it should indicate
the state of the network connection at all times.
The protocol that the objects in this system speak to each
other should be as simple and as flexible as possible.
Leave room to add commands, because you never know
when you might decide to add something. Make sure to
build in responses where appropriate, like the “hi” and
“bye” responses from the server. Keep the messages
unambiguous, and if possible, keep them short as well.
Finally, make sure you’ve got a reliable way to test the
system. Simple tools like the telnet client and the test
server will save you much time in building every multi-
player server, and help you get to the fun sooner.
Now you’ve seen examples of both asynchronous client-
server exchanges (the HTTP system in Chapter 4) and
synchronous exchanges (the chat server here). With those
two tools, you can build almost any application in which
there’s a central server and a number of clients. For the
next chapter, you’ll step away from the Internet and take a
look at various forms of wireless communication.
X
The basic structure of the clients and server in this chapter can be used any time that
you want to make ...