Today's project shows off how you can take advantage of the new TCP/UDP socket supporting coming in the Windows Phone Mango release. You'd like taking an existing game and plugging in multiplayer support might be hard, or that socket support is a little much for you, but this post shows that it isn't and there's no need to fear...

Windows Phone Peer-to-Peer Multiplayer Game using Sockets in XNA

One of the new features for the app platform in Windows Phone Mango is TCP and UDP Sockets. In this blog post, I'll talk about using this to augment an existing game to add peer-to-peer multiplayer over WiFi using UdpAnySourceMulticastClient. Phones running the game on the same WiFi network automatically discover one another and the players just appear on the screen.

The game itself is from another sample, the Windows Phone 7 Platformer Starter Kit from David Rousset's blog.

The changes are to add code to run UDP Multicast sockets and to enable multiplayer.

The source code for the full project is attached in the zip file below.

PlatformerGame.cs: This contains the game code and is where the sockets are initialized, and where the sends and receives are handled.

UdpAnySourceMulticastChannel.cs: This contains the UDP multicast sockets code for joining the group, sending and receiving data.

OtherPlayer.cs: This is a modification of Player.cs to add other players to the game.

...

Hope this helps show a simple way to communicate from phone to phone and demonstrate the power of sockets. Happy developing!