WP客户端socket接收中文乱码问题
服务器端:
是c++写的执行sql语句从oracle数据库中查询内容通过socket发送;c++编译默认编码是unicode
_RecordsetPtr Rp=connect.GetRecordset(sql);
_variant_t varUserName;
string strUserName;
varUserName = Rp->GetCollect ("TICKETCODE");//票号
strUserName=strUserName+(char *)_bstr_t(varUserName);
strUserName=rtrim(strUserName);
send(clientSocket,strUserName.c_str(),strUserName.length(),0);
string response = "something";
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
socketEventArg.RemoteEndPoint = _socket.RemoteEndPoint;
socketEventArg.SetBuffer(new Byte[MAX_BUFFER_SIZE], 0, MAX_BUFFER_SIZE);
socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(delegate(object s, SocketAsyncEventArgs e)
response = Encoding.UTF8.GetString(e.Buffer, e.Offset, e.BytesTransferred);//个人猜测是这里设置编码有问题
response = response.Trim('\0');
response = Encoding.unicode.GetString(e.Buffer, e.Offset, e.BytesTransferred);