向网络编程高手请问Indy通信过程中出现的乱码有关问题 Indy V10.5.6
向网络编程高手请教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);
服务端:
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);