From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Tcp reconnect

Hi guys

 

I am using TCP Listen to connect the host pc and my RT target to transmit videostream and some more data. Then, while the RT target is still running, there are times that the host pc is being disconnected to the tcp network. When I run the host pc again, it was unable to receive the videostream and the data that comes from the RT target. I discovered that I need to restart the RT target to reconnect the host pc in the tcp network. However, this takes a lot of time. Is there any way to reconnect the host pc to the RT target again without restarting the RT target? 

0 Kudos
Message 1 of 9
(4,095 Views)

What does your RT code do when it loses the connection? You will need to put some error handling/connection recovery code in your RT application to try and re-establish the connection once it is lost. Can you post your code?

0 Kudos
Message 2 of 9
(4,084 Views)

How is the RT handling the disconnect from the Host? 

 

Are you looking for new connections when a disconnect is detected? 

0 Kudos
Message 3 of 9
(4,081 Views)

Currently, I do not have any error handling code once the host is disconnected. What kind of code shall I create once the host is disconnected? Sorry I do not have any idea since I am just new to coding in Labview. Thank you for all your suggestions

 

By the way I cannot post the code at the moment since my laptop is not with me. Maybe tomorrow I can post it

0 Kudos
Message 4 of 9
(4,071 Views)

 


@jasonrenz wrote:

Currently, I do not have any error handling code once the host is disconnected. What kind of code shall I create once the host is disconnected? Sorry I do not have any idea since I am just new to coding in Labview. Thank you for all your suggestions

 

By the way I cannot post the code at the moment since my laptop is not with me. Maybe tomorrow I can post it


Without seeing what your RT code architecture looks like, we cant really give you concrete advice, but wherever you are handling the connection, if your read or write functions return an error other than just a timeout(or if you miss a heartbeat, if your setup includes one) I would close the connection, then attempt to reopen. If the reopen fails, wait a short amount of time, then attempt to reopen again - continue this until a valid connection is established. 

 

I would put all this code in its own loop - with some mechanism for passing data received to the rest of your application, and receiving transmission requests from the rest of the application. 

0 Kudos
Message 5 of 9
(4,053 Views)

@paul.r wrote:

I would put all this code in its own loop - with some mechanism for passing data received to the rest of your application, and receiving transmission requests from the rest of the application. 


Ditto.  I typically have one loop to do nothing but read from the port and pass the data on to whoever needs it.  If I get a timeout or error, I close the port and wait for a connection again.  A very simple State Machine will do this with no issues.  My little trick is I like to store the reference in an Action Engine and let that handle the writing to the port (any other loop can use it to send data to the client).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 9
(4,044 Views)

How will the RT target know if the connection of the host PC is lost? 

0 Kudos
Message 7 of 9
(4,026 Views)

The attached file is the code that I am using

0 Kudos
Message 8 of 9
(4,024 Views)

@jasonrenz wrote:

How will the RT target know if the connection of the host PC is lost? 


The simplest way is to use a watchdog setup.  The idea is you have a "ping" message you have your PC send to the RT and have the RT reply.  This ping should be sent every so often (I use a couple of seconds).  So if a read times out, you can assume the connection was lost.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 9
(4,007 Views)