Send struct over socket in C

后端 未结 2 1379
不知归路
不知归路 2020-12-18 02:22

I am developing a client/server program and my client has to send messages to the server.

Sample message C structure:

struct Reg         


        
2条回答
  •  失恋的感觉
    2020-12-18 02:49

    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.

提交回复
热议问题