使用 Google Play 游戏服务,我正在尝试实现回调,这样,如果发送消息有问题,那么我需要解决它(因为每个玩家“将”他们的出价“传递”给下一个玩家,以及所有其他玩家需要查看通过出价的玩家是什么)
我想我会尝试使用以下方法为该轮消息实例化一个 RealTimeReliableMessageSentListener,以便我可以判断消息是否被每个人发送和接收:
(我将调用返回的 tokenID 添加到 ArrayList,然后检查删除每个 tokenID,因为它返回以跟踪何时收到本轮的所有消息)
@Override
public void sendReadyToPlay() {
dLog("Sending ReadyToPlay");
// Broadcast that I'm ready, and see that they are ready
if (!mMultiplayer){
return; // playing against computer
}
// First byte in message indicates whether it's a final score or not
mMsgBuf[0] = (byte) ('R');
readyToPlayTokens.clear();
// Send to every other participant.
for (Participant p : mParticipants) {
dLog("Participant:" + p.getParticipantId());
if (p.getParticipantId().equals(mMyId)) {
continue;}
if (p.getStatus() != Participant.STATUS_JOINED){
continue;
}
readyToPlayTokens.add(mHelper.getGamesClient().sendReliableRealTimeMessage(new RealTimeReliableMessageSentListener() {
@Override
public void onRealTimeMessageSent(int statusCode, int tokenId, String recipientParticipantId){
dLog("onRealTimeMessageSent number two and size is: " + readyToPlayTokens.size());
if(readyToPlayTokens.contains(tokenId)){
readyToPlayTokens.remove(tokenId);
}
dLog("onRealTimeMessageSent number two and size is: " + readyToPlayTokens.size());
if (statusCode != GamesClient.STATUS_OK) {
mGHInterface.onRealTimeMessageReceived("RTPProblem:" + recipientParticipantId);
} else if (readyToPlayTokens.size() == 0) {
mGHInterface.beginRound();
}
}
}, mMsgBuf, mRoomId, p.getParticipantId()));
dLog("sent to:" + p.getParticipantId());
}
}
我几乎每次都可以看到消息从一个设备发送到另一个设备,因此我可以看到消息正在通过,但是 RealTimeReliableMessageSent 侦听器只有大约 50-60% 的时间被触发,这不是很可靠的!:)
谁能看到我可能做错了什么来阻止听众可靠地发射?