Lukas Skala wrote:
> hello,
> I have server application based on TWSocketServer, clients are derived
> from TWSocketClient class.
> I need disconnect inactive clients. I'm not sure how to disconnect
> client, I'm using this:
> procedure DisconnectMyClient(i: Integer);
> var
>   C: TTcpSrvClient;
>   {TTcpSrvClient = class(TWSocketClient)}
> begin
> C := Server.Client[I] as TTcpSrvClient;
> C.Close;

That works, though "Server.Client[I].Close" would be enough.

If want to close clients while iterating over the client list
make sure you iterate from high index down to zero like:
for I := Server.ClientCount -1 downto 0 do

A more brutal method to enforce client close was

> C.Free; {Is this correct? sometimes it will throw access violation
> here....} end;

That's wrong, don't do that. Client objects are freed and 
removed from the internal client list when they are closed
or disconnected automatically by the server.

> I'm using ICS v6.

You should update to ICSv7.

> I did notice that Server.OnClientDisconnect event is not triggered
> when client is not closed correctly (e.g. client is plugged of
> ethernet). 

That's the expected behaviour. 

> Is there any possibility to detect and/or disconnect these
> clients automatically?

Implement an idle timeout at the server side. Let the client send
some keep alive data in intervals so the server knows a client is
still there.   

Arno Garrels
To unsubscribe or change your settings for TWSocket mailing list
please goto
Visit our website at

Reply via email to