My application needs to send/receive xml data via a tcp socket. There is no way to include any kind of a fixed-length header containing message length. As far as I understand, data transmitted over tcp can come to the receipient like this.
-
<messa
-
ge><content
-
>hi</content>
-
</message>
But somehow this never happens meaning that data sent with one Send() operation (assuming it’s shorter or equal than socket buffer size) is always read completely with one Receive() operation. Is the above scenario possible given that socket buffers of the endpoints are large enough and never exceeded?
This can easily happen if there is a proxy between. If we assume there is no proxy, the client will receive the same packets as the server sends. If you send data in pieces less than TCP MSS of your link, the client will probably receive it in one piece.
However, I would not rely on this. It is easy to tell the end of an XML message by seeing the close tag (
</message>), so it’s easy to parse XML from a stream.