好的。我收到一次数据包,但它的块被触发了两次。例如:
我有一个这样的块:
if (object instanceof InitTheGame) {
System.out.println("STARTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT");
awaitOpponent.dismiss();
isInQueue = false;
matchRunning = true; // handles the while loop inside the thread that sends data to the server
isInMatch = true; // handles view (checks for this if we exit the app)
// new GamePacketSender().start();
casualGameHolder.gameLoop.start();
new Sensor(act, casualGameHolder.gameLoop);
touchListener = new TouchListener(casualGameHolder.gameLoop);
this_layout.setOnTouchListener(touchListener);
act.runOnUiThread(new Runnable() {
public void run() {
GameStartCountdown countdown = new GameStartCountdown(4000,1000);
countdown.start();
countdownDialog = new Dialog(act);
countdownDialog.show();
countdownDialog.setCancelable(false);
}
});
}
在控制台(LOG_TRACE)中,我可以看到,数据包已收到一次,但“STARTTTTTTTTTTTTTTTTT”System.out 显示两次,倒计时显示两次等。
我不想发布整个代码,因为它庞大且难以理解。这可能是由于服务器上的缓冲区溢出引起的,或者可能是因为我在一台设备上同时打开了两个连接?如果有任何有 Kryonet 经验的人,我将不胜感激。