I'm writing a C++ app that uses sockets and I have no problem sending an recieving, but am having trouble separating the differnt types of messages i'm sending.
I have several classes from which I need to send data using overloaded stream operators.
when I say
I recieve this: "0hi world", but I want to recieve "0", then "hi world".Code:socket << myObject; ... operator<<(Socket &socket, myObject mo) { socket << mo.myInt; // 0 socket << mo.myString; // "hi world" }
Is there any way to force the sockets to read and write in sync? without encoding value delimiters or forceing fixed-width data.
I was thinking encoding delimiters may be more efficient at least on the per-object transmissions, but there will still be a point when I need to force read and write to sync between sending objects. (this is also multi-threaded with lots of user input jumping around)
fixed-width data is out of the question becase there are so many types of clasess with so many types of data that need to be sent.
Thanks!