客户端用DELPHI,服务端用DOTNET;
DOTNET那边全部用UTF-8接受和发送;DELPHI这边如下:
     udpClient.Send(UTF8Encode(txtMsg.Text));
     str1:=updClient.ReceiveString();
     ustr := UTF8Encode(str1);
       txtMsg.Text := ustr;
结果为:发送没问题,但接收到中文是乱码,这个该怎么处理?

解决方案 »

  1.   

    怎么都是UTF8Encode,接受回来时是什么编码的,是不是该解码了
      

  2.   

    从DOTnet发送回来,也是UTF8:
     //发送数据(DOTNET发送)
                    recData = Encoding.UTF8.GetBytes("欢迎 DOTNET!");
                    _service.Send(recData, recData.Length, _receivePoint);
      

  3.   

      udpClient.Send(UTF8Encode(txtMsg.Text));
      str1:=updClient.ReceiveString();
      ustr := UTF8Encode(str1);//这里应该要UTF8Decode进行解码,而不是使用UTF8Encode来编码  txtMsg.Text := ustr;
      

  4.   

    按楼上的做法可以了,如下:
    var
     wstr:WideString;
     str1:string;
    begin       updClient.Send(UTF8Encode(txtMsg.Text));
         str1:=updClient.ReceiveString();
         wstr := UTF8Decode(str1);
           txtMsg.Text := wstr;第一天用DELPHI写程序有点蒙,谢了