Einzelnen Beitrag anzeigen

Hobbycoder

Registriert seit: 22. Feb 2017
930 Beiträge
 
#3

AW: TIdTCPClient "Conntection closed gracefully" obwohl Connected

  Alt 25. Jul 2019, 16:53
Okay, dann suche ich am falschen Ende.
Aber warum schließt der Server die Verbindung?

Delphi-Quellcode:
procedure TForm2.idtcpsrvr1Execute(AContext: TIdContext);
var
  text: string;
  tmpClient: TClient;
  JsonObj: TJSONObject;
begin
  text:=AContext.Connection.Socket.ReadLn;
  if mmo1.Lines.Count=0 then
    mmo1.Lines.Add(text) else mmo1.Lines.Insert(0, text);
  if Copy(Text.ToLower, 1, 4)='openthen
  begin
    JsonObj:=TJSONObject.Create;
    try
      JsonObj.ParseJSONValue(Copy(text, Pos('#', text)+1, length(text)));
      tmpClient:=TJSON.JsonToObject<TClient>(JsonObj);
      if ClientList.IndexOfGUID(tmpClient.GUID)=-1 then
        ClientList.AssignAsNew(tmpClient) else
        tmpClient.AssignTo(ClientList[ClientList.IndexOfGUID(tmpClient.GUID)]);
    finally
      if Assigned(tmpClient) then
        tmpClient.Free;
      JsonObj.Free;
    end;
    AContext.Connection.Socket.WriteLn('users#'+ClientList.GetAsJSONString); //<-kommt beim Client nicht an
    AContext.Connection.Socket.WriteLn('exit#'); //<-kommt beim Client nicht an
  end;
end;
Läuft auch durch, aber wird direkt TIdTCPServer.OnDisconnect ausgelöst. Nur warum? Sollte die Verbindung nicht aufrecht gehalten werden?
Gruß Hobbycoder
Alle sagten: "Das geht nicht.". Dann kam einer, der wusste das nicht, und hat's einfach gemacht.
  Mit Zitat antworten Zitat