I’m programming my own TCP client, and it is acting a bit weird.
The way the client works is by checking if the last byte of the received bytes is a \0 character. If it is, it converts the previous data in the buffer into text, and triggers an event with that text as the event’s argument.
However, something odd happens if I attempt to send 2 strings at the same time. In that case, they actually get received as one string, which is weird if you ask me.
How can I fix this?
I didn’t include code samples since it would be quite large to include. If you insist, add a comment and request it, and I’ll post it.
TCP is a stream so what you are describing is totally normal when you send multiple packets from one side of the connection, the other side may receive everrything at the same time.
Well the windows kernel is in fact fighting AGAINST you in this, as it try as much possible to concatenate packets. If you want to disable this (It’s called the Nagle Algorithm) from the side that is sending the data :
But TCP will always represent a stream, so you should be prepared for it.
In your case it mean that you should parse the returned string, find all
'\0'and send an event for each of them.