Using the built-in networking in XNA, all networking centers on the NetworkSession. Once you have an active session (you can check the MSDN link abve or AppHub examples for creating and joining sessions) you have two types of players in the session:
- LocalNetworkGamer - players on your Xbox participating in the session
- NetworkGamer - players attached to other Xboxes participating in the session
The NetworkSession has three properties that let you find out who is who. LocalGamers gives you only players connected to the local Xbox, RemoteGamers gives you all players connected to other Xboxes in the session, and AllGamers gives you both.
Data is sent across the network through the session by calling SendData on a LocalNetworkGamer. There are several overloads of this method - some send data to all players in the session (including the person sending it), others send data only to target gamers. When you call NetworkSession.Update the framework collects all the outgoing SendData requests since the last update and sends the appropriate packets to the correct machines. NetworkSession.Update also receives all earlier sent data and stores it in a buffer per gamer. To actually do something with the data sent over the network you need to pull it out of these buffers; this is done by calling ReceiveData on all the LocalNetworkGamers in your network session. If you don't call ReceiveData you will eventually have issues where the incoming data buffer is full and overflows.