网络通信中,发送结构体方法

方法一:
发送端:
-------------------------------------------------------
structST_HISTORY
{
intEcgValue;
intEegValue;
CharAlarm;
CStringstr;
intWave[3][20];
};

ST_HISTORYstHistory;
charszSend[MAX_LENGTH]={0};
memcpy(szSend,&stHistory,sizeof(stHistory));
send(socket,szSend,strlen(szSend),0);

接收端:
------------------------------------------------------------
charszRecv[MAX_LENGTH]={0};
intnRecv=recv(socket,szRecv,MAX_LENGTH,0);
szRecv[nRecv]='/0';
ST_HISTORYstHistory;
memcpy(&stHistory,szRecv,sizeof(stHistory));



方法二:

【网络通信中,发送结构体方法】直接传送和接收结构体
structtagStruct{
//
}SendStruct;
send(socketID,(char*)&SendStruct,sizeof(SendStruct),0);

structtagStruct{
//
}RcevStruct;
recv(socketID,(char*)&RecvStruct,sizeof(RecvStruct),0);

    推荐阅读