为什么CSocket接收INT数据会错误..在线等待...
lzd 2002-10-07 04:39:45 客户端代码
struct OpenPoint
{
short Game_Function;
char UserName[20];
int mOpenPoint;
};
CSocket m_pSocket;
OpenPoint m_OpenPoint;
char* CharUserName="daf"
ZeroMemory(&m_OpenPoint,sizeof(OpenPoint));
m_OpenPoint.Game_Function=2;
strcpy(m_OpenPoint.UserName,CharUserName);
m_OpenPoint.UserName[strlen(CharUserName)]='\0';
m_OpenPoint.mOpenPoint=100;
int send = 0;
while(send<sizeof(OpenPoint))
{
int nCharSend=m_pSocket->Send((void*)(&m_OpenPoint+send),sizeof(OpenPoint)-send,0);
send+=nCharSend;
}
服务器代码
struct OpenPoint
{
char UserName[20];
int mOpenPoint;
};
CSocket m_pServerSocket;
OpenPoint m_OpenPoint;
short temp;
m_pServerSocket->Receive(&temp,sizeof(short),0);
switch(temp)
{
case 0:
{
break;
}
case 2:
{
ZeroMemory(&m_OpenPoint,sizeof(OpenPoint));
int receive = 0;
while(receive<sizeof(OpenPoint))
{
int nCharSend=m_pServerSocket->Receive((void*)(&m_OpenPoint+receive),sizeof(OpenPoint)-receive,0);
receive+=nCharSend;
}
}
为什么接收到的m_pServerSocket.mOpenPoint=6553600(本来应该是100)而m_pServerSocket.UserName则正常?