How can I pass an XML output result / other object types in C++ through sockets, and make sure that the data are not corrupted? The output size can be something between 100KB – 2MB in size. The UNIX sys/socket library would only allow me to send basic data types (like character string) as the socket message.
I know that Boost AISO library is also a good library for socket programming but I am not sure if it will allow me to send XML output / object types through sockets. Speed/performance is a major concern, and my server intends to have multiple clients connected to it. Any ideas / concerns on how to handle this? Do you have some existing example codes that does the same thing: sending object data type through C++ sockets? Could you please explain the approach that you did? Some example codes / pseudocode would be really helpful indeed.
If you want check that the received data is correct, you should use CRC or other error detection codings. However sockets try to guarantee it and you can feel free to check the data again. Also in network transmission, Speed and Reliability are tradeoff, you should take something between them depending on your application.
Second, for send data objects, What do you need is Marshaling or Serialization. You can marshal data objects before sending it, and create data object when receiving it in other side. You can do it yourself with your protcols or you can use ready libraries.
A practice that marshals data object to XML is this. (Note: I didn’t test it myself)