18,363
社区成员




void respondClient(SOCKET sockClient, byte charb[], int length, boolean finalFragment) {
byte buf[100] = "";
int first = 0x00;
cout << "first:" << first << endl;
int tmp = 0;
if (finalFragment) {
first = first + 0x80;
cout << "first:" << first << endl;
//first = first + 0x1;
first = first + 0x2;
cout << "first:" << first << endl;
}
buf[0] = first;
tmp = 1;
cout << ">>>>>>>>>>>>>>>>>>>>>>>数组长度:" << length << endl;
unsigned int nuNum = (unsigned)length;
if (length < 126) {
buf[1] = length;
tmp = 2;
}
else if (length < 65536) {
buf[1] = 126;
buf[2] = nuNum >> 8;
buf[3] = length & 0xFF;
tmp = 4;
}
else {
//数据长度超过65536
buf[1] = 127;
buf[2] = 0;
buf[3] = 0;
buf[4] = 0;
buf[5] = 0;
buf[6] = nuNum >> 24;
buf[7] = nuNum >> 16;
buf[8] = nuNum >> 8;
buf[9] = nuNum & 0xFF;
tmp = 10;
}
cout << "tmp:" << tmp << endl;
for (int i = 0; i < length; i++) {
buf[tmp + i] = charb[i];
printf("要发送的数据字节:%d\n", charb[i]);
}
char charbuf[100] = "";
memcpy(charbuf, buf, length + tmp);
send(sockClient, charbuf, 100, 0);
}