Jon*_*ert 11 multiplayer gksession ios game-center
我在应用程序中成功使用GKMatch已经有一段时间了.我一直在追逐游戏并偶尔停止游戏,并将其跟踪到正在发送但未收到的数据包.这只是偶尔发生,但我似乎无法追查它为什么会发生.
所有消息都使用GKSendDataReliable发送.
记录显示数据包正在从一台设备成功发送,但从未在目标设备上接收.
//Code sample of sending method....
//self.model.match is a GKMatch instance
-(BOOL) sendDataToAllPlayers:(NSData *)data error:(NSError **)error {
[self.model.debugger addToLog:@"GKManager - sending data"];
return [self.model.match sendDataToAllPlayers:data withDataMode:GKSendDataReliable error:error];
}
Run Code Online (Sandbox Code Playgroud)
...
//Code sample of receiving method....
// The match received data sent from the player.
-(void)match:(GKMatch *)match didReceiveData:(NSData *)data fromPlayer:(NSString *)playerID {
[self.model.debugger addToLog:@"GKManager - received data"];
[super didReceiveData:data fromPlayer:playerID];
}
Run Code Online (Sandbox Code Playgroud)
我所看到的是周期性地(可能是100个消息中的1个)在没有错误的情况下从'sendDataToAllPlayers'方法发送,但是接收设备永远不会遇到'didReceiveData'方法.我的理解是,使用GKSendDataReliable应该发送消息,然后在收到确认之前不会发送另一个消息.未收到消息,但从同一设备发送新消息.
发送方法返回'YES'并且错误是nil,但didReceiveData永远不会被命中......!
有没有人见过这个?有没有人有任何想法这可能是什么?我不知道我还能做些什么来调试这个.
我确认了这个错误.我做了一个示例项目,一直在重现这个问题:https://github.com/rabovik/GKMatchPacketLostExample.我在一个弱的互联网连接上测试它(带有Wi-Fi的iPad 3和带有EDGE的iPhone 4S;两者都在iOS 6.1.3上),并且一些数据包经常丢失而没有任何来自Game Center API的错误.此外,有时设备停止接收任何数据,而另一个仍然成功发送和接收消息.
因此,如果我们确定存在错误,唯一可行的解决方法是添加额外的传输层以实现真正可靠的传输.
我为此编写了一个简单的lib:https://github.com/rabovik/RoUTP.它保存所有已发送的消息,直到确认每个接收到的消息,重新发送丢失并缓冲接收到的消息,以防序列中断.在我的测试组合中,"RoUTP + GKMatchSendDataUnreliable"甚至比"RoUTP + GKMatchSendDataReliable"更好(当然比纯粹的GKMatchSendDataReliable更好,但这并不可靠).
| 归档时间: |
|
| 查看次数: |
931 次 |
| 最近记录: |