udpclient接受中文数据时出现乱码

puny 2010-05-25 05:06:52
客户端用DELPHI,服务端用DOTNET;
DOTNET那边全部用UTF-8接受和发送;

DELPHI这边如下:
udpClient.Send(UTF8Encode(txtMsg.Text));
str1:=updClient.ReceiveString();
ustr := UTF8Encode(str1);
txtMsg.Text := ustr;
结果为:发送没问题,但接收到中文是乱码,这个该怎么处理?
...全文
294 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
puny 2010-05-25
  • 打赏
  • 举报
回复
按楼上的做法可以了,如下:
var
wstr:WideString;
str1:string;
begin

updClient.Send(UTF8Encode(txtMsg.Text));
str1:=updClient.ReceiveString();
wstr := UTF8Decode(str1);
txtMsg.Text := wstr;

第一天用DELPHI写程序有点蒙,谢了
僵哥 2010-05-25
  • 打赏
  • 举报
回复
udpClient.Send(UTF8Encode(txtMsg.Text));
str1:=updClient.ReceiveString();
ustr := UTF8Encode(str1);//这里应该要UTF8Decode进行解码,而不是使用UTF8Encode来编码 txtMsg.Text := ustr;
puny 2010-05-25
  • 打赏
  • 举报
回复
从DOTnet发送回来,也是UTF8:
//发送数据(DOTNET发送)
recData = Encoding.UTF8.GetBytes("欢迎 DOTNET!");
_service.Send(recData, recData.Length, _receivePoint);
bdmh 2010-05-25
  • 打赏
  • 举报
回复
怎么都是UTF8Encode,接受回来时是什么编码的,是不是该解码了

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧