Lukas Skala wrote:
> hello,
> thank for quick and useful response.
> i'll try to upgrade to V7 now because i'm still getting error
> (catched by Server.OnBgException event), I'm getting AccessViolation
> or InvalidOperation exceptions.

Sounds like you are accessing pointers or objects when they have been
already freed. 

> These errors occurs after disconnecting client by server (i'm using
> timer - in same way as you adviced me).

Huh? I haven't advised how to use a TTimer.
Using a timer might be tricky and the reason for your problem.
An example of using a timer to detect client timeouts is
THttpServer that encapsulates a TWSocketServer component.
It uses method TWSocketServer.Disconnect() to close timed out
clients in procedure THttpServer.HeartBeatOnTimer(Sender: TObject);. 

> I have tried to add C.Free
> call but I have thought it was nonse (you have confirmed it me).

Yes, the server gives and the server takes ;)

> 
> One question for sure:
> 
> When I call Client.Close the Client will be freed automatically
> (destructor of Client will be called)?

Yes, TWSocketServer manages the client objects, do not free them,
just Close or Disconnect them, that's all. 

-- 
Arno Garrels

> 
> thank you again
> have a nice day
> lukas skala
> 
> 
> 
> Dne 21.7.2011 17:29, Arno Garrels napsal(a):
>>  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
>>     Server.Client[I].Close;
>> 
>>  A more brutal method to enforce client close was
>>  Server.Disconnect().
>> 
>>>  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.
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to