1. 定长结构体
-
struct Sendbuf
-
{
-
char SendDate[1024]; //定长的数据
-
};
-
-
const char *msg = "Think You!!!"; //这里是要发送的内容
-
-
int SendDateklength = sizeof(Sendbuf) + strlen(msg)+1; //计算要发送的总的长度 (结构体长度+发送内容的长度)
-
Sendbuf SendDate;
-
-
SendDate.length = strlen(msg);
-
strcpy_s(SendDate.SendDate,strlen(msg) + 1,msg);
//将结构体首地址转为(const char*),发送
-
send(socket,(const char *)&SendDate,SendDateklength,0)
2. 变长结构体
http://blog.csdn.net/zhaobangyu/article/details/8904005