简体   繁体   English

通过远程服务器上的套接字读取的数据为空

[英]Data read through socket on a remote server is empty

We have a client-server software made in java. 我们有一个用Java开发的客户端服务器软件。

Client part sends a string: 客户部分发送一个字符串:

dataOutputStream.writeUTF("User");

Server reads this string: 服务器读取以下字符串:

String login = dataInputStream.readUTF();
System.out.println("User accepted: " + login);

The server part is launched on amazon ec2. 服务器部分在Amazon EC2上启动。 We have 2 offices and from 1 office everything works fine: server accepts the socket and read the data correctly, but from another office the server accepts the socket, however reads empty strings. 我们有2个办公室,从1个办公室一切正常:服务器接受套接字并正确读取数据,但是服务器从另一个办公室接受套接字,但是读取空字符串。

All the ports are opened for our IPs in the EC2 control panel. 在EC2控制面板中,为我们的IP打开了所有端口。

I have installed WireShark and checked if correct data goes to the server and yes, it is correct. 我已经安装了WireShark,并检查是否有正确的数据发送到服务器,是的,它是正确的。

Both offices are running the same client part. 两个办公室都运行相同的客户端部分。 The only difference i know is that office 1 have Win 7 and 8 (works on both, tried different machines) and office 2 have Win 10 (doesn't work, tried different machines) 我知道的唯一区别是办公室1拥有Win 7和8(在两个机器上均可工作,尝试使用不同的计算机),而办公室2拥有Win 10(无法正常工作,已尝试使用不同的计算机)。

What could be the reason of such behavior? 这种行为的原因可能是什么? What we could check / try to resolve it? 我们可以检查/尝试解决什么?

DataInputStream.readUTF() cannot possibly return an empty String , by which I assume you mean a String object whose length() is zero, unless an empty string was presented to writeUTF() at the other end. DataInputStream.readUTF()可能无法返回空String ,我假设您的意思是一个length()为零的String对象,除非在另一端将空字符串提供给writeUTF() It can however throw an EOFException if the data has somehow been truncated in flight. 但是,如果数据在运行中被截断,则可能引发EOFException

You'll have to post some code to elucidate this further. 您必须发布一些代码以进一步阐明这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM