Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Oct : Re: Best method of keep-alive?

www.cryer.info
Managed Newsgroup Archive

Re: Best method of keep-alive?

Subject:Re: Best method of keep-alive?
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Mon, 2 Oct 2006 13:42:37

"Jamie Dale" <j.dale@turboz.net> wrote in message
news:4521516d@newsgroups.borland.com...

> I was wondering if anyone has a idea or method for implementing a
> keep-alie system using TIdTCPClient and TIdTCPServer?

This has been discussed many many times before.  Please go to
http://www.deja.com and search through the newsgroup archives.  Or go to
Indy's own newsgroups on the news://news.atozed.com server and browse
through the old messages that are still on the server (there are no archives
for Indy's server).

> I'm pretty familiar with the general theory - One end can send a 'ping'
> and the other replies with a 'pong'.

Yes, that is one way to do it.

> My question is what is the best way to do this

There is no "best" way to implement it.  It is whatever you are comfortable
with, and what fits into your actual protocol.

> how can one end of the connection recognise if the time for
> the reply has expired?

It is each side's responsibility to keep track of how much time has elapsed
between packets.  In general, you need to take advance of the connection's
ReadTimeout property to know when no data has arrived for a given period of
time.

> 1) Server sends 'ping' with a serial number - IE Ping := 'ping:123';

The client should be the one to send the pings, not the server.  This way,
the client is actively telling the server that it wishes to remain connected
to the server.  If the server does not receive the ping for a given period
of time, it can close the connection.  If the server were the one to send
the pings, then it does not work as well.

Also, you don't need serial numbers in the pings at all, since the server
would only be interested in knowing that data is still flowing through the
connection in general, not necessarily what the data actually is.

> Client does not respond. Timer kicks in and checks array for replies
> that are outstanding and increments a count.

Since Indy servers are multi-threaded to begin with, there is no need for a
ping array.  Each individual thread can manage its own ping locally.

> Server then sends the same ping/serial again.

If a ping is not replied to in a timely manner, the ping should not be
attempted again.  Simply disconnect the connection immediately.  The client
can then reconnect to the server if it wishes to.


Gambit

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive