2 lianghaoming7 lianghaoming7 于 2016.09.09 00:07 提问

websocket协议 C++的问题

已经有编码代码
char * PackData(CString message)
{
unsigned char * contentBytes = NULL;
CString temp;
ConvertGBKToUtf8(temp,(char *)message.GetString());

        if (temp.GetLength() < 126){
            contentBytes =(unsigned char *)malloc(temp.GetLength()+2);
            contentBytes[0] = 0x81;
            contentBytes[1] = (unsigned char)temp.GetLength();
            strcpy((char *)contentBytes+2,temp.GetString());
        }else if (temp.GetLength() < 0xFFFF){
            contentBytes = (unsigned char *)malloc(temp.GetLength()+4);
            contentBytes[0] = (unsigned char)0x81;
            contentBytes[1] =(unsigned char) 126;
            contentBytes[2] = (unsigned char)((unsigned char)temp.GetLength() & 0xFF);
            contentBytes[3] = (unsigned char)((unsigned char)temp.GetLength() >> 8 & 0xFF);
            strcpy((char *)contentBytes+4,temp.GetString());
        }else{
            // 暂不处理超长内容  
        }

        return (char *)contentBytes;
    }  

            跪求解码代码

1个回答

devmiao
devmiao   Ds   Rxr 2016.09.09 00:13
Csdn user default icon
上传中...
上传图片
插入图片