Formatting Messages

Whenever you are dealing with designing a network for a game or game-like application, you are guaranteed to be dealing with at least two types of messages. These are often referred to as state messages and server messages. A state message is a message that will directly affect your game engine, such as a player moving or opening a chest. Server messages deal with the glue that holds everything together, such as connections, disconnections, pings, and errors.

It becomes important to quickly sort these messages to different handlers. It is a good design pattern to keep the parsing of these messages in different places. After all, you don't want to be scanning all your chat messages in a first-person shooter for client timeout ...

Get Beginning iOS Game Center and Game Kit: For iPhone, iPad, and iPod touch 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.