Instance Method

match:didReceiveData:fromRemotePlayer:

Called when data is received from a player.

Declaration

- (void)match:(GKMatch *)match didReceiveData:(NSData *)data fromRemotePlayer:(GKPlayer *)player;

Parameters

match

The GKMatch object that received the data.

data

The bytes sent by the player.

player

The GKPlayer object identifying the player that sent the data.

Discussion

Your game defines its own format for data packets it transmits and receives over the network. Listing 1 shows one way to handle an incoming message from another player.

Listing 1

Handling a specific message type

- (void)match:(GKMatch *)match didReceiveData:(NSData *)data fromRemotePlayer:(GKPlayer *)player
{
    Packet *p = (Packet*)[data bytes];
    if (p.messageKind == PositionMessage)
        // Handle a position message.
}

See Also

Receiving Data from Other Players

- match:didReceiveData:forRecipient:fromRemotePlayer:

Called when data is received by a player from another player.