读书人

向网络编程高手请问Indy通信过程中出现

发布时间: 2012-02-03 22:02:47 作者: rapoo

向网络编程高手请教Indy通信过程中出现的乱码问题 Indy V10.5.6
服务端:
Procedure TInformationServer.OnTCPExecute(AContext: TIdContext);
var
sCommand: string;
begin
AContext.Connection.IOHandler.ReadLn(TIdTextEncoding.UTF8,TIdTextEncoding.UTF8);
sCommand:=uppercase(AContext.Connection.IOHandler.ReadLn);
If sCommand='FILELIST' then
begin

sCommand:=AContext.Connection.IOHandler.ReadLn;
end;
If fMemo<>nil Then
fMemo.Lines.Add(sCommand);
end;


客户端:
IdTCPClient1.Connect;
IdTCPClient1.Socket.WriteLn(TIdTextEncoding.UTF8);
IdTCPClient1.Socket.WriteLn('Filelist');
IdTCPClient1.Socket.WriteLn('美女');
IdTCPClient1.Disconnect;

以上代码纯粹做网络测试,程序中客户端能与服务端连通,服务端能收到"Filelist",但“美女”两个字无法收到!

[解决办法]
把这行注释掉试试。
IdTCPClient1.Socket.WriteLn(TIdTextEncoding.UTF8);

读书人网 >.NET

热点推荐