【发布时间】:2013-07-10 20:19:56
【问题描述】:
我正在尝试将玩家的位置 (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)。但是其他一切都正确发送和接收?
【问题讨论】:
-
请在本站发布您的相关代码。
-
嗯?您可以将代码粘贴到代码格式化块中,而不是链接到包含屏幕截图 URL 的粘贴箱吗?
-
你能给我们展示一下重现这个问题的代码吗?例如没有不需要的 GUI 代码。
-
嗯,你的意思是,你可以发送一个 int 而你需要发送两个?
-
你如何将玩家的位置发送给客户端?