Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 发送INT,接收错误数据_Java_Sockets - Fatal编程技术网

Java 发送INT,接收错误数据

Java 发送INT,接收错误数据,java,sockets,Java,Sockets,我正在尝试从服务器向客户端发送播放器的位置(x,y)。其他一切似乎都正常,但这两个整数不行。我可以发送其他整数,例如3456,它将接收3456。但是这些都不行 服务器Java代码: public void sendAccountInformation() throws IOException { dos.write(player.id); main.log(player.id); dos.println(player

我正在尝试从服务器向客户端发送播放器的位置(x,y)。其他一切似乎都正常,但这两个整数不行。我可以发送其他整数,例如3456,它将接收3456。但是这些都不行

服务器Java代码:

public void sendAccountInformation() throws 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(); } public void loadAccount() throws 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); } public void sendAccountInformation()引发IOException{ dos.write(player.id); main.log(player.id); dos.println(player.username); main.log(player.username); 写(player.x); main.log(player.x); dos.write(player.y); main.log(player.y); 写入(player.mapid); main.log(player.mapid); dos.flush(); } 服务器输出:

0 sdfsdffsd 544 384 0 0 SDFSD 544 384 0 以上是应发送的正确信息

客户端Java代码:

public void sendAccountInformation() throws 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(); } public void loadAccount() throws 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); } public void loadAccount()引发IOException{ int id=dis.read(); main.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 0 SDFSD 63 63 0
如您所见,两个整数(544和384)被更改为(63和63)。但是其他一切发送和接收都是正确的吗?

我认为您应该尝试使用并编写和阅读
int

请将您的相关代码发布在这个网站上。嗯?您可以将代码粘贴到一个代码格式块中,而不是链接到一个包含屏幕截图URL的粘贴站吗?您可以向我们展示一个复制此问题的代码的简短部分吗?e、 g.没有不需要的GUI代码。好吧,你的意思是,你可以发送一个int,而你需要发送两个int?你如何将玩家的位置发送给客户端?我将尝试并发布结果。谢谢工作完美。谢谢大家的帮助。:)有人告诉我如何将这个问题设置为“已解决”