Geeks With Blogs
Josh Reuben
·        XNA communication must by default be lightweight – if you are syncing game state between players from the Game.Update method, you must minimize traffic. That game loop may be firing 60 times a second and player 5 needs to know if his tank has collided with any player 3 and the angle of that gun turret. There are no WCF ServiceContract / DataContract niceties here, but at the same time the XNA networking stack simplifies the details. The payload must be simplistic - just an ordered set of numbers that you would map to meaningful enum values upon deserialization.
·        XNA allows you to create and join multiplayer game sessions, to manage game state across clients, and to interact with the friends list
·        Dependency on Gamer Services - to receive notifications such as sign-in status changes and game invitations
·        two types of online multiplayer games: system link game sessions (LAN) and LIVE sessions (WAN).
·        Minimum dev requirements: 1 Xbox 360 console + Creators Club membership to test network code - run 1 instance of game on Xbox 360, and 1 on a Windows-based computer
Network Sessions
·        A network session is made up of players in a game + up to 8 arbitrary integer properties describing the session
·        create custom enums – (e.g. GameMode, SkillLevel) as keys in NetworkSessionProperties collection
·        Player state: lobby, in-play
Session Types
·        local session - for split-screen gaming - requires no network traffic.
·        system link session - connects multiple gaming machines over a local subnet.
·        Xbox LIVE multiplayer session - occurs on the Internet. Ranked or unranked
Session Updates
·        NetworkSession class Update method - must be called once per frame.
·        performs the following actions:
o   Sends the network packets.
o   Changes the session state.
o   Raises the managed events for any significant state changes.
o   Returns the incoming packet data.
·        synchronize the session à packet-received and state-change events à no threading issues
Session Config
·        Session host - gaming machine that creates the session. XNA handles host migration
·        NetworkSession properties: AllowJoinInProgress , AllowHostMigration
·        NetworkSession groups: AllGamers, LocalGamers, RemoteGamers
Subscribe to NetworkSession events
·        GamerJoined
·        GamerLeft
·        GameStarted
·        GameEnded – use to return to lobby
·        SessionEnded – use to return to title screen
Create a Session
session = NetworkSession.Create(
        sessionProperties );
Start a Session
if (session.IsHost)
    if (session.IsEveryoneReady)
       foreach (var gamer in SignedInGamer.SignedInGamers)
            gamer.Presence.PresenceMode =
Find a Network Session
AvailableNetworkSessionCollection availableSessions = NetworkSession.Find(
availableSessions.AllowJoinInProgress = true;
Join a Network Session
NetworkSession session
= NetworkSession.Join(
Sending Network Data
var packetWriter = new PacketWriter();
foreach (LocalNetworkGamer gamer in session.LocalGamers)
    // Get the tank associated with this player.
    Tank myTank = gamer.Tag as Tank;
    // Write the data.
    // Send it to everyone.
    gamer.SendData(packetWriter, SendDataOptions.None);
Receiving Network Data
foreach (LocalNetworkGamer gamer in session.LocalGamers)
    // Keep reading while packets are available.
    while (gamer.IsDataAvailable)
        NetworkGamer sender; 
        // Read a single packet.
        gamer.ReceiveData(packetReader, out sender); 
        if (!sender.IsLocal)
            // Get the tank associated with this packet.
            Tank remoteTank = sender.Tag as Tank; 
            // Read the data and apply it to the tank.
            remoteTank.Position = packetReader.ReadVector2();
End a Session
if (session.AllGamers.Count == 1)
        Aim to minimize payload, reliable in order messages
        Send Data Options:
o   Unreliable, out of order -(SendDataOptions.None)
o   Unreliable, in order (SendDataOptions.InOrder)
o   Reliable, out of order (SendDataOptions.Reliable)
o   Reliable, in order (SendDataOptions.ReliableInOrder)
o   Chat data (SendDataOptions.Chat)
        Voice support – NetworkGamer properties: HasVoice ,IsTalking , IsMutedByLocalUser
Posted on Tuesday, June 28, 2011 5:16 AM Graphics Programming | Back to top

Comments on this post: XNA Multiplayer Games and Networking

# re: XNA Multiplayer Games and Networking
Requesting Gravatar...
i enjoy your article. great job. keep it simple
Left by deny on Jan 25, 2012 7:14 PM

# re: XNA Multiplayer Games and Networking
Requesting Gravatar...
For the guy aloft me, the IP is that of the computer that is active it. If you're active both the server and the applicant on the aforementioned IP, again you can use the "Home" IP which is The anchorage is authentic in the server cipher but you don't charge to change this. birthday sms
Left by yasir on Jul 13, 2012 10:58 PM

# re: XNA Multiplayer Games and Networking
Requesting Gravatar...
I just capital to let you apperceive I am award this tutorial actual helpful. Probably wont accept abundant to appearance as for my own plan for a while as I am active with Uni honours activity being at the moment. jogos de fazenda But I will let you apperceive if I anytime get annihilation up and running
Left by jimmy on Aug 11, 2012 8:53 AM

# re: XNA Multiplayer Games and Networking
Requesting Gravatar...
I adulation you xD I had a lot of account how to handle the diffrent affectionate of packets i accept to forward and recieve in my bold but none of it works accomplished and now...finally i begin your your cipher with abundant comments for every step!! And so it was realy simple to fabricated my bold playable over internet! I accept to say it afresh I LOVE YOU
Left by ed on Oct 20, 2012 9:03 AM

# re: XNA Multiplayer Games and Networking
Requesting Gravatar...
Your site provided us with valuable information to work with. Each & Thanks a lot for sharing.
By | Berita Terkini
Left by iyus on Feb 21, 2013 6:36 AM

# re: XNA Multiplayer Games and Networking
Requesting Gravatar...
Great information! I learned a lot from this ideas. - Bath Planet
Left by Michelle David on Jan 11, 2017 12:24 PM

Your comment:
 (will show your gravatar)

Copyright © JoshReuben | Powered by: