I’ve been working on the multiplayer part of the game lately. I’ve decided to pull out of the other aspects of the programming to concentrate on this because I fear it might be too difficult to add later.
So far, I’ve had some initial success with System Link networking. System link allows you to network between two machines (either two Xbox 360s, one PC and one Xbox 360, or two Windows PCs). I do have two Xboxes but I decided not to go that route because I do not have two televisions (and I didn’t want to buy another one or a monitor). Using two Xboxes also means to have two LIVE accounts with Creator’s Club activated on each. You can get a free 12 month trial of creator’s club by registering for Dream Build Play 2009, but I didn’t choose this route ultimately because of the TV issue. So that means I needed to quickly port my game to Windows. It wasn’t too hard and mostly involved putting keyboard support in place so I didn’t have to hook up a second controller to my PC.
So I started work integrating a lot of the sample code from the Network Game State Management sample off the XNA website. It is a good sample and really helped me get a lot of the boilerplate coding done (i.e. making a menu system to select matching, creating sessions, the lobby, readying up, etc.). This sample also shows how to handle progress and error checking in an elegant manner.
Once I had the menus all configured, it was time to go after the actual gameplay. For network traffic, I basically send two types of packets: regular state updates and ad-hoc messages. State updates are like a “heartbeat” update of each player’s state (player position, for example). It is sent every few frames in an unreliable and out-of-order fashion. This is the quickest form of internet traffic and it makes sense considering that this data is updated on each machine very frequently. The second form of packet is “ad-hoc” and sent only when there’s new state updates, such as when the player selects a letter or confirms a word. For these types of messages, I chose to use reliable send because the packets must arrive at the receiver. We cannot have a packet drop that contains critical information.
I have yet to test this networking code simulating latency and packet loss. I hear a typical packet loss statistic is 2-10% over XBox LIVE. Latencies can be 100-200ms on average or even longer. I will probably test up to 200ms with a 10% loss. I hope it works!