Question

I made a server in which the sending of the data itself is made like this:

PrintWriter writer = new PrintWriter(new OutputStreamWriter(clientSocket.getOutputStream(), "UTF-8"));
writer.write(json);
writer.close();

How can i know if the server has indeed sent the entire message?

In my client (written in C#), when the json string is long, then i get a certain amount of bytes which is less then the length of the json string (for some reason always a max length of 183 bytes).

The client is using asynchronous connection. How can i know if the server indeed sent the entire message? Is it possible i need to divide a long message into chunks and send them one after the other? I'm just not sure if the problem is in the server or in the client.

Was it helpful?

Solution

What I did in the end was adding an header to the message with the size of the message and then checked on the C# side if the size of the received message is the size of the message and if it's not, ask again the socket for data until I got the full message.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top