Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to implement KEEP_ALIVE with Indy TIdTCPClient?


This question is answered.


Permlink Replies: 2 - Last Post: Feb 14, 2017 1:04 AM Last Post By: Adrian Bors
Adrian Bors

Posts: 12
Registered: 3/25/13
How to implement KEEP_ALIVE with Indy TIdTCPClient?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 13, 2017 7:34 AM
Hi,

I am using two threads to communicate with PLC. One thread is continuously reading data from PLC and other thread is on click event based write to the PLC. My writer thread is most of the time under sleep and awakes whenever user wants to write to plc (click on button).

Indy : I am using TIdTCPClient to read/write from plc.
Builder : C++ , XE5
Indy version: 10.6.0.5040.

I found out that socket in writer thread disconnects after certain time of idle. I guess operating system disconnects socket after some idle time. I understood that, I have to implement KEEP_ALIVE with TIdTCPClient to avoid disconnect the socket automatically. Can any one please suggest me how to implement KEEP_ALIVE with Indy-TIdTCPClient?

Thanks,

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to implement KEEP_ALIVE with Indy TIdTCPClient?
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 13, 2017 11:11 AM   in response to: Adrian Bors in response to: Adrian Bors
Adrian wrote:

Indy version: 10.6.0.5040.

That is an old version. The current version is 10.6.2.5395.

I found out that socket in writer thread disconnects after certain
time of idle. I guess operating system disconnects socket after
some idle time.

No, it does not. More likely, the PLC is the one disconnecting on its end
when you don't send it commands for awhile.

I understood that, I have to implement KEEP_ALIVE with
TIdTCPClient to avoid disconnect the socket automatically.

That depends on what the PLC actually expects from you. There is no requirement
in TCP itself to use keep-alives. But protocols designed on top of TCP may
have such a requirement.

Can any one please suggest me how to implement KEEP_ALIVE
with Indy-TIdTCPClient?

Simply have your writer thread wake itself up periodically so it can send
whatever keep-alive command the PLC is expecting. What is so hard about
that?

--
Remy Lebeau (TeamB)
Adrian Bors

Posts: 12
Registered: 3/25/13
Re: How to implement KEEP_ALIVE with Indy TIdTCPClient?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 14, 2017 1:04 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...

Can any one please suggest me how to implement KEEP_ALIVE
with Indy-TIdTCPClient?

Simply have your writer thread wake itself up periodically so it can send
whatever keep-alive command the PLC is expecting. What is so hard about
that?

--
Remy Lebeau (TeamB)

Thanks for your suggestion Remy. I can use your suggestion to solve my problem.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02