我正在尝试将玩家的位置 (x, y) 从服务器发送到客户端。其他一切似乎都有效,但不是这两个整数。我可以发送其他整数,例如 3456,它会收到 3456。但这些都行不通。
服务器Java代码:
公共无效 sendAccountInformation() 抛出 IOException {
dos.write(player.id);
main.log(player.id);
dos.println(player.username);
main.log(player.username);
dos.write(player.x);
main.log(player.x);
dos.write(player.y);
main.log(player.y);
dos.write(player.mapid);
main.log(player.mapid);
dos.flush();
}
服务器输出:
0 sdfsdffsd 544 384 0
以上是应该发送的正确信息。
客户端 Java 代码:
公共 void loadAccount() 抛出 IOException {
int id = dis.read();
main.player = new Player(id, main);
main.log(id);
main.player.username = dis.readLine();
main.log(main.player.username);
main.player.x = dis.read();
main.log(main.player.x);
main.player.y = dis.read();
main.log(main.player.y);
main.player.mapid = dis.read();
main.log(main.player.mapid);
}
客户端输出:
0 sdfsdffsd 63 63 0
可以看到,两个整数(544 和 384)变成了(63 和 63)。但是其他一切都正确发送和接收吗?