IdUDPServer中文汉字乱码 及IdTCPClient

本文详细介绍了使用Indy库解决IdUDPServer1中文汉字乱码问题的方法,通过设置IndyTextEncoding_OSDefault字符编码,成功实现了中文数据的正确发送和接收。同时,还提供了关于发送和接收字节数据、处理UDP读取操作的示例代码,以及TCP客户端发送数据的实现方式。此外,文章还涉及了如何在不同场景下利用Indy库进行数据交互,并提供了相关链接和社区讨论作为参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

官网

http://www.indyproject.org/docsite/html/frames.html?frmname=topic&frmfile=TIdTCPServer_OnExecute.html

 

IdUDPServer1中文汉字乱码,用IndyTextEncoding_OSDefault字符编码就解决问题了

IdUDPServer1.Send(1.1.1.1,8080,'中国人',IndyTextEncoding_OSDefault);

 

发送字节

IdUDPServer1.SendBuffer(const System::UnicodeString AHost, const System::Word APort, const Idglobal::TIdBytes ABuffer);

 TIdBytes 就是TBytes就是TByteDynArray

 

 udp bytes byte

procedure TForm1.IdUDPServer1UDPRead(AThread: TIdUDPListenerThread; const AData: TIdBytes; ABinding: TIdSocketHandle);
begin
   lastMsg := BytesToString(AData, IndyTextEncoding_OSDefault);

end;

 

TCP,IdTCPClient

IndyTextEncoding

IdTCPClient1.IOHandler.WriteLn(sendData,IndyTextEncoding(TEncoding.ANSI)); 

 

bs:TBytes;

setlength(bs,8);

IdTCPClient1.IOHandler.Write(TIdBytes(bs));

 

c++

String rstr = BytesToString(AData, IndyTextEncoding_UTF8());

https://stackoverflow.com/questions/13839094/how-to-read-all-bytes-from-server-using-indy-client-in-delphi

https://forums.embarcadero.com/thread.jspa?threadID=211952

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值