Markus Humm wrote:
> Hello,
> 
> I've a TCP connection (simple TWSocket, only one PC may connect) and
> want to implement some keep-alive now. The rest of the application
> seems to work well, but the keepalive killed my whole day now without
> much success.

That's not difficult.

> 
> Currently I'm doing this in the OnSessionAvailable of the server:
> 
> Where a is a TWScket descendant:
> 
> if not assigned(a) then
> begin
>    a:=MyTWSocket.Create;
>    a.dup(...); // here get's the connection assigned
> end;
> 
> That works.
> My protocol is now such that the client sets up a timer when he
> connects to the sever which will send every few seconds a dummy
> request which the server simply has to echo back.

OK

> The server also has
> a timer set up in the OnSessionConnected method which will check
> wether a keepalive request has been received within the time or not.

I would count other data sent by the client as well.

> If not he triggers the following:
> 
> a.abort;

OK, can be Close as well

> FreeAndNil(a);

Oh, that's not a good idea, free it in SessionClose event.

> 
> The other socket of the server still is in the listening state where
> I've left it since he was told to listen.

OK
 
> The client will notice it in its own timer because his keepalive
> requests won't be answered anymore.
> If the client detects this he
> starts another timer which tries every second to establish a
> connection to the same adress.

If the network cable is not plugged SessionClose event will be triggered
when you send something. If you detect a timeout call Close and 
SessionClose will be triggered as well.

>From SessionClose post a custom message and from the message handler
reconnect.

--
Arno Garrels [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to