So,
nun hab ich euch genug genervt. Habe das doch noch hinbekommen. Das OnExecute sollte so aussehen.
Trotzdem danke an alle
Delphi-Quellcode:
procedure TfMain.IdTCPServer1Execute(AContext: TIdContext);
var
Cli :TIdTCPClient;
IOhnd :TIdIOHandlerStack;
Data :string;
Len :Int64;
Buf :TIdBytes;
begin
try
if ( PeerIPs.IndexOfName(AContext.Connection.Socket.Binding.PeerIP)<>-1 ) then begin //bekannt
GblUrl:=PeerIPs.Values[AContext.Connection.Socket.Binding.PeerIP];
end else Exit;
Cli := nil;
try
// #### Create IOHandler ####
IOhnd:=TIdIOHandlerStack.Create(nil);
{ Create & Connect to Server }
Cli:=TIdTCPClient.Create(nil);
Cli.IOHandler:=IOhnd;
Cli.Host := GblUrl;
Cli.Port := 80;
{ Connect to the remote server }
Cli.Connect;
{ Read/Write loop }
repeat
{ Read data from Client }
if ( AContext.Connection.IOHandler.InputBuffer.Size>0 ) then begin
Len :=AContext.Connection.IOHandler.InputBuffer.Size;
Data:=AContext.Connection.IOHandler.ReadString(Len);
{ Write it to the Server }
Cli.IOHandler.Write(Data);
end;
{ Read data from Server }
if ( Cli.IOHandler.InputBuffer.Size>0 ) then begin
Len:=Cli.IOHandler.InputBuffer.Size;
Cli.IOHandler.ReadBytes(Buf,Len,False);
{ Write it to the Server }
AContext.Connection.IOHandler.Write(Buf,Len);
{ Release system slizes }
end;
SleepEx(1, True);
Cli.CheckForGracefulDisconnect(False);
AContext.Connection.CheckForGracefulDisconnect(False);
until (not AContext.Connection.Connected) or (not Cli.Connected);
finally
if Assigned(Cli) then
begin
Cli.Disconnect;
Cli.Free
end;
{ Disconnect real client }
AContext.Connection.Disconnect;
if ( Assigned(IOhnd) ) then begin
IOhnd.Free;
end;
end;
except
end;
end;