I am using Java for socket communication. The server is reading bytes from the client like this:
InputStream inputStream;
final int BUFFER_SIZE = 65536;
byte[] buffer = new byte[BUFFER_SIZE];
String msg="";
while (msg.indexOf(0)==-1 && (read = inputStream.read(buffer)) != -1)
{
msg += new String(buffer, 0, read);
}
handleMessage(msg)
There is a problem when a client is sending multiple messages at once the server mixes the messages e.g.
MSG1: <MyMessage><Hello/>nul
MSG2: </MyMessage><MyMessage><Hello again /></MyMessage>nul
So the tail of Message 1 is part of Message 2. The null represents the java nul symbol.
Why does the inputstream mix the messages?
Thanks in advance!