Einzelnen Beitrag anzeigen

gsachs

Registriert seit: 7. Okt 2025
1 Beiträge
 
#1

ICS 9.5 Problem TCPServer.DisconnectAll

  Alt 7. Okt 2025, 11:54
Hallo,
bei einer kleinen Anwendung mit TCPIP Kommunikation möchte ich die Kommunikation sicher beenden, bevor ich das Programm beende.
Ich habe eine TWSocketServer Komponente, die Verbindung zu einem remote client hat. Beim Aufruf von ServerSocket.DisconnectAll gibt es eine Exception. Wenn ich mit dem Debugger (vor der Exception) hineingehe, scheint der Grund auch klar zu sein.
Hier ist der ICS Code :
Delphi-Quellcode:
procedure TCustomWSocketServer.Disconnect(Client: TWSocketClient; ErrCode: Integer = WSAECONNABORTED); { V9.4 added ErrorCode }
var
    Msg : TMessage;
    PIdRec : PClientIdRec;
begin
    FillChar(Msg, SizeOf(Msg), 0);
{ angus V7.00 pass CliId to WMClientClosed so correct client is closed  }
    try
        New(PIdRec);
        PIdRec^.PClient := Client;
        PIdRec^.CliId := Client.CliId;
        Msg.WParam := ErrCode;
        Msg.LParam := LPARAM(PIdRec);
        WMClientClosed(Msg); // don't send message since called by DisconnectAll and expect immediate response
    except
    end;
 end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TCustomWSocketServer.DisconnectAll; { angus V6.01 }
begin
    while [COLOR="Red"]ClientCount > 0[/COLOR] do
        Disconnect(Client[0], WSAECONNABORTED); { V9.4 added ErrorCode }
end;
DisconnectAll verwendet den ClientCount Wert, um Disconnect n Clients mal aufzurufen. Der ist in meinem Fall 1 und das bleibt er auch. Ich vermute, er sollte in der Disconnect Routine dekrementiert werden.
  Mit Zitat antworten Zitat