I have a client and server program where I want to send an entire struct from the client and then output the struct member "ID" on the server.
I have done all the connecting etc and already managed to send a string through:
send(socket, string, string_size, 0);
So, is it possible to send a struct instead of a string through send()? Can I just replace my buffer on the server to be an empty struct of the same type and go?
Welll... sending structs through the network is kinda hard if you are doing it properly.
Carl is right - you can send a struct through a network by saying:
But here's the thing:
So the solution people often propose is to have a routine that serializes the struct. That is, it sends the struct one data member at a time, ensuring that the client and server only send() and recv() the exact specified number of bytes that you code into your program.