Java socket 两个客户端进行数据交流遇到问题
服务器进行的数据交流:while(true){score=fromPlayer1.readInt();System.out.println("play1score=:"+...
服务器进行的数据交流:
while (true) {
score=fromPlayer1.readInt();
System.out.println("play1 score=:"+score);
toPlayer2.writeInt(score);
System.out.println("play1发送成功");
score=fromPlayer2.readInt();
System.out.println("play2 score=:"+score);
toPlayer1.writeInt(score);
System.out.println("play2发送成功");
}
}
客户端:
try {
while(true)
{
int player = fromServer.readInt();
if (player == PLAYER1) {
sendMove();
receiveMove();
}
else if (player == PLAYER2) {
sendMove();
receiveMove();
}
// Continue to play
}
}
为啥执行交流对于play1执行接收的时候总是失败,,就卡在这 展开
while (true) {
score=fromPlayer1.readInt();
System.out.println("play1 score=:"+score);
toPlayer2.writeInt(score);
System.out.println("play1发送成功");
score=fromPlayer2.readInt();
System.out.println("play2 score=:"+score);
toPlayer1.writeInt(score);
System.out.println("play2发送成功");
}
}
客户端:
try {
while(true)
{
int player = fromServer.readInt();
if (player == PLAYER1) {
sendMove();
receiveMove();
}
else if (player == PLAYER2) {
sendMove();
receiveMove();
}
// Continue to play
}
}
为啥执行交流对于play1执行接收的时候总是失败,,就卡在这 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询