开发者

Sending Data to Other Players - Game Center

I am developing a simple game center multiplayer game. i did manage almost everything except sending messeage to players. what i mean, i can invite player to play game, game is starts etc.

regarding apple documentation i am using following method to send data but it' doesn't work at all.

const char开发者_运维问答 *bytes = "123";  
NSData *packet = [NSData dataWithBytes:&bytes length:3];
[myMatch sendDataToAllPlayers: packet withDataMode: GKMatchSendDataUnreliable error:nil];

if possible a working sample would be great. many thanks.

I did pretty much same.

NSError *errorTransmit; 
const char *bytes = "asd";  
NSData *packet = [NSData dataWithBytes:&bytes length:3];
[myMatch sendDataToAllPlayers: packet withDataMode: GKMatchSendDataUnreliable error:&errorTransmit];    
if (errorTransmit != nil)

    NSLog(@"Error sending data to peers: %@", [errorTransmit localizedDescription]);
}

but when code reach NSLog(@"Error sending data to peers: %@", [errorTransmit localizedDescription]); I am getting Program received signal: “EXC_BAD_ACCESS”. that's why i can't see what is going on.


Must confess I've yet to use the GameCenter bits and pieces, but as a general approach I'd have thought you might want to see if there were any errors being generated. As such, if you use something like...

NSError *transmissionError;

[myMatch sendDataToAllPlayers: packet
                 withDataMode: GKMatchSendDataUnreliable
                        error: &transmissionError];

if(transmissionError != nil) {
   NSLog(@"Transmission error: %@", transmissionError);
}

...you might get a clue what's going wrong.

Incidentally, I'm currently away from a compiler so apologies for any typos in the above. :-)


I cannot see anything wrong here, I am using this code:

NSData *data = nil;
NSError *error = nil;
int packet = 777;
data = [[NSData alloc] initWithBytes:&packet length:sizeof(int)];
[self.mMatch sendDataToAllPlayers:data withDataMode:GKMatchSendDataReliable: &error];

and it works

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜