c++ as3.0 socket 封包和拆包,用C++当做服务器,向客户端发了一串消息,客户端怎么拆包呢?
st_Head*head=newst_Head;head->iType=123456;head->iLen=sizeof(head->iType)*sizeof(int)...
st_Head * head = new st_Head;
head->iType = 123456;
head->iLen = sizeof(head->iType) * sizeof(int);
UserInfo * user = new UserInfo;
user->id = 1;
user->name = "lyh";
user->age = 24;
char charbuffer[500];
string type = "|";
sprintf(charbuffer,"%d%s%d%s%d%s%d%s%s",head->iType,type,head->iLen,type,user->id,type,user->age,type,user->name);
stPackA * pack = new stPackA;
pack->data = charbuffer;
//strcpy(pack->data,charbuffer);
MyMassage * massage = *sendDataList.begin();
SOCKET st = massage->st;
char chr[30] = {0};
strcpy(chr,massage->chr);
delete massage;
cout << pack->data;
cout << strlen(pack->data) * sizeof(char);
m_socket.SendMsg(st,pack->data,strlen(pack->data) * sizeof(char)); 展开
head->iType = 123456;
head->iLen = sizeof(head->iType) * sizeof(int);
UserInfo * user = new UserInfo;
user->id = 1;
user->name = "lyh";
user->age = 24;
char charbuffer[500];
string type = "|";
sprintf(charbuffer,"%d%s%d%s%d%s%d%s%s",head->iType,type,head->iLen,type,user->id,type,user->age,type,user->name);
stPackA * pack = new stPackA;
pack->data = charbuffer;
//strcpy(pack->data,charbuffer);
MyMassage * massage = *sendDataList.begin();
SOCKET st = massage->st;
char chr[30] = {0};
strcpy(chr,massage->chr);
delete massage;
cout << pack->data;
cout << strlen(pack->data) * sizeof(char);
m_socket.SendMsg(st,pack->data,strlen(pack->data) * sizeof(char)); 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询