Hello,
I'm working on a C++ client/server project where XML strings are passed over a TCP/IP connection. My question is about the proper way to indicate the complete string has been received. I was thinking of null terminated strings or sending the length of the XML string first, so the client/server can tell when a complete string is received.
The client can send GET/SET commands, and the server can reply, as well as send a continuous stream of results. For example: client sends <GET ID="DATA1" />
and server replies <ID="DATA1" VAL="..." />
Or the server can send a continuous stream:
<ID="DATA1" VAL="..." />
<ID="DATA2" VAL="..." />
<ID="DATA3" VAL="..." />
<ID="DATA4" VAL="..." />
In which case the client might receive in a single Read:
<ID="DATA1" VAL="..." /><ID="DATA2" VAL="..." />
Or if a large amount of data were sent it might take multiple Read's to read the whole string.
Using a null termination character seems a bit simplistic (and breaks if string is unicode?) and sending a length value seems awkward as well:
20<ID="DATA1" VAL="1" />
or <length=20><ID="DATA1" VAL="1" />
This must have been solved for TX/RX of HTML files, I just can't seem to figure it out.
I'm using MFC C++ (legacy code) for the server and .Net C++/CLI or C# for the client.
Any help is greatly appreciated!