简体   繁体   中英

Java Socket : Write to client not working

I currently have a problem with a Java server thingy.

It's a simple TCP server which send images. 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.

If the server works fine with telnet then your server is fine.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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