简体   繁体   English

Java Socket:写入客户端无法正常工作

[英]Java Socket : Write to client not working

I currently have a problem with a Java server thingy. 我目前有一个Java服务器问题。

It's a simple TCP server which send images. 这是一个发送图像的简单TCP服务器。 Problem is, I don't have the code of the client program... Moreover, it seems that there is no way to check the client socket for writing event nor the amount of data already sent to the client. 问题是,我没有客户端程序的代码......而且,似乎没有办法检查客户端套接字是否写入事件,也没有检查已发送到客户端的数据量。

Do someone have any idea about what could prevent the client to get the image correctly ? 有人知道什么可以阻止客户端正确获取图像吗?

Here's my code : 这是我的代码:

byte[] response = process ( cmd );

if ( response == null )
{
    controlSock.close();
    dataSock.close();
    stop = true;
}
else if ( dataSock != null )
{
   dos.write( response );
   dos.flush();
}

By the way, the server is working fine with Telnet. 顺便说一句,服务器与Telnet正常工作。

If the server works fine with telnet then your server is fine. 如果服务器与telnet正常工作,那么你的服务器就可以了。

The problem is more likely to be in the assumptions the client is making are not the same as yours. 问题更可能出在客户所做的假设与您的假设不同。 for example the client might assume you are sending the size first in big or little endian format (as an int, short or long) Perhaps it expects the name of the file/image in some format as well. 例如,客户端可能会假设您首先以大端或小端格式发送大小(作为int,short或long)也许它也希望以某种格式显示文件/图像的名称。

The only way to know this for sure is to read the code for the client or ask someone who knows what assumptions the client makes. 确实知道这一点的唯一方法是阅读客户端的代码或询问知道客户端做出什么假设的人。

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

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