LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to prevent a TCP connection being closed when the VI that opened it finishes.

Solved!
Go to solution

Hello everyone.

 

I am developing an application based around servers and clients communicating over TCP in LabVIEW 2012.

 

When the server/client opens a TCP connection ,it launches an asynchronosly running "connection handler", to which it passes the connection reference which then takes over all the communcation. This all works fine.

 

However - I have a situation where a client's connection handler can be informed of another "new" server. I would like it to open the connection (to see if it is still valid) and then pass this connection reference back to the client's main code to spawn a new connection handler. This prevents me locking up the Client's main code with a long-ish timeout if the "new" server is not actually accepting connections.

 

The issue is that if the connection handler that opened up the connection to the "new" server is stopped, then it appears to destroy the reference that it opened. This means that the other connection handler that was merrily communcating with the "new" server has its TCP communciations closed (I get an Error code 1 on a write).

 

I have created an example to demonstrate the issue which should be used as follows:

 

1. Run server.vi - it will listen for a connection on the port specifed on its BD.

2. Run CH Launcher.vi - it will open a connection to the server and pass the TCP reference to an instance of Connection Handler.vi which it launches.

3. The Connection Handler should send data to the Server

4. Stop the CH Launcher.vi

5. The Connection Handler.vi will error.

 

Any suggestions would be much appreciated.

 

Cheers

 

John

 

0 Kudos
Message 1 of 5
(5,040 Views)

On further investigation it would appear that this might not be possible as LabVIEW ensures that any references (TCP, Queues etc) that a VI opens are closed automatically when the VI goes out of memory.

 

In my case I have changes the part of the code that opens the TCP connection to a VI that has the same lifetime as the main VI so that any connections that have been opened will only be closed automatically when the main VI stops.

 

Cheers

 

John

 

 

0 Kudos
Message 2 of 5
(4,993 Views)
Solution
Accepted by topic author John_Neutron

Dont perform the opening and closing the TCP connection in subVI. Do this in master VI.

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 3 of 5
(4,989 Views)

John_Neutron escreveu:

[...] 

In my case I have changes the part of the code that opens the TCP connection to a VI that has the same lifetime as the main VI so that any connections that have been opened will only be closed automatically when the main VI stops.


 

And what are the effects? You are still facing the same problem or closing the connection only when the whole applicaton stops solved your problem?

 

Regards

Mondoni
0 Kudos
Message 4 of 5
(4,985 Views)

Sorry for the slow reply.

 

Ensuring that I open the TCP connection using a VI that has the same lifetime (or longer) than the connection lifetime ensures that LabVIEW does not clean it up.

 

So it is not actually possible to "prevent a TCP connection being closed when the VI that opened it finishes", you just have to work around it.

 

Cheers

 

0 Kudos
Message 5 of 5
(4,875 Views)