DataPackage 同时存在于服务器端与客户端。两边保持一致。
struct DataPackage
{
int age;
char name[32];
};
DataPackage dp= {60,"张三"};
send(_cSock, (const char*)&dp, sizeof(DataPackage),0);
---------------------------
客户端:
char recvBuf[128]={};
int nlen = recv(_sock,recvBuf,128,0);
if(nlen>0)
{
DataPackage *dp= (DataPackage *)recvBuf;
printf("接收到的数据:Age=%d ,Name=%s", dp->age,dp->name);
}