LocalNetworkGamer.ReceiveData Method (Byte[], Int32, NetworkGamer)

Reads the next incoming packet using the specified values.

Namespace: Microsoft.Xna.Framework.Net
Assembly: Microsoft.Xna.Framework.Net (in microsoft.xna.framework.net.dll)

public int ReceiveData (
         byte[] data,
         int offset,
         out NetworkGamer sender


Type: Byte
Storage for the network packet data.
Type: Int32
Offset, in bytes, to begin reading data.
Type: NetworkGamer
[OutAttribute] Gamer who sent this packet.

Return Value

Number of bytes read from the network packet. Returns 0 if no packet is available.

Exception typeCondition
ArgumentExceptionThe specified array is too small to receive the incoming network packet.
ArgumentNullException data is null.
ArgumentOutOfRangeException offset cannot be larger than the amount of data available for storage.

Be sure to call ReceiveData for all incoming data for all local gamers, even if the data is to be discarded. Any time data is sent to a local network gamer, the incoming data queue will grow until the data is read. If the data is not read using ReceiveData the performance of the application will degrade as the data queue grows in size.

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);
        // Discard the data, or use packetReader.Read* to process the data.
    gamer.SendData(packetWriter, SendDataOptions.None);

ReceiveData copies the packet data into the array specified by data, returning the number of bytes read. If several independent packets are available, only one is returned for each ReceiveData call.

Xbox 360, Windows 7, Windows Vista, Windows XP

Community Additions