I am developing a client/server program and my client has to send messages to the server.
Sample message C structure:
struct Reg
While the code will work if you send and recv on the same endian machine - your client and server should ideally perform a host to network endian conversion to maintain coherence when inspecting clientPid.
sizeof(regn)
gives size of your complete structure Registration
, wheras sizeof(data)
is size of pointer on your machine that is 4 bytes (data
should be pointer of Registration
type).
In expression:
memcpy(data, ®n, sizeof(regn));
^ ^
| value variable of struct type
is pointer
also notice in printf, .
is used to access elements e.g. regn.multicastGroup
.