delphi2009(Lazarus)中indy10 的Idtcpserver收发中文的解决办法。
来源:互联网 发布:dev c 如何创建c语言 编辑:程序博客网 时间:2024/06/04 19:49
用Idtcpserver组件收发中文,关键就是转码,要将编码转为UTF-8格式。
接收消息
procedure TfrmMain.IdTCPServerExecute(AContext: TIdContext);
var BufStr:AnsiString;
buflen:integer;
begin
if (AContext.Connection.Connected) then
begin
try
CoInitialize(nil);
try
BufStr:=AContext.Connection.IOHandler.ReadLn(TIdEncoding.en8Bit);
LogMsg('read: '+BufStr+' '+'IP:'+AContext.Connection.Socket.Binding.PeerIP+':'+intToStr(AContext.Connection.Socket.Binding.PeerPort));
except
AContext.Connection.Disconnect;
end;
buflen:=Length(BufStr);
finally
CoUninitialize();
end;
end;
end;
发送消息
procedure TfrmMain.SendClientMessage(AContext: TIdContext; sMsg: string);
var sClientID:string;
begin
if TIdContext(AContext).Connection.Connected then
begin
sClientID:=TIdContext(AContext).Connection.Socket.Binding.PeerIP+':'+intToStr(TIdContext(AContext).Connection.Socket.Binding.PeerPort);
AContext.Connection.IOHandler.WriteLn(sMsg,TIdEncoding.en8Bit);
LogMsg('Send: '+sMsg+' '+'IP:'+sClientID);
end;
end;
- delphi2009(Lazarus)中indy10 的Idtcpserver收发中文的解决办法。
- delphi2009(Lazarus)中indy10 的Idtcpserver断开客户端连接报错问题的解决办法
- Indy10中idTcpServer和idTcpClient的异常解决
- 从Indy9升级到Indy10时IdTcpServer的变化
- 从Indy9升级到Indy10时IdTcpServer的变化
- 从Indy9升级到Indy10时IdTcpServer的变化
- Lazarus(0.9.26)+ Indy10 系列(一)——获取最新的Indy源码
- Lazarus(0.9.28)+ Indy10 系列(二)——获取最新的Indy源码
- Lazarus(0.9.30)+ Indy10 系列(三)——获取最新的Indy源码
- Delphi中关于idtcpserver的使用解答(转)
- Lazarus安装Indy10控件
- 白皮书:Delphi2009中新的DataSnap
- 关于idtcpserver的使用
- Lazarus(0.9.30)+ Indy10 系列(五)——安装Indy控件,重新编译Lazarus
- Lazarus中TrayIcon的图标运用(Windows)
- Indy10的问题
- indy10的教程
- Indy10的使用例子
- memset函数详解
- ld编译选项以及lds链接文件格式
- MySQL存储过程调试工具-dbForge Studio for MySQL
- Spark&Spark性能调优实战
- JSON未定义
- delphi2009(Lazarus)中indy10 的Idtcpserver收发中文的解决办法。
- Mac系统打开应用程序文件夹的方法+解决Android studio出现fetching android sdk component超时打不开的问题
- [IOS] 经常被忽视的 UITextField 的属性
- 编写程序数一下1到100的所有整数中出现多少次数字9
- JavaScript验证用户输入的是字符或数字
- VC按钮切换界面
- 2-2-2 判断语句-if-else新例子?
- 二叉树 求宽度
- 电子商务网站的设计与实现(三):四大子系统,登录-账务-前端-后端