12-08-2012 12:14 PM
We have an application that acts as a control panel for a customer's device.
It connects to the device using TCP-IP.
It can be configured to connect as a server (listener) or as a client.
The user of this applicaiton must have the ability to disconnect from the device and point and connect to a different device at a different IP and port.
When the user tries to connect to a device but can not (the device is not ready or the IP address is wrong) he wants to abort the connection, change the settings then restart the attempt to connect.
How do I stop the TCP-IP Listen or TCP-IP Open Connection VIs? We typically use a timeout of a couple seconds and this is a long delay for a respond to the operator when he wants to abort the connection attempt.
12-08-2012 05:25 PM
You can stop Wait on Listener by killing the listener using TCP Close. You'll want to replace TCP Listen with TCP Create Listener and TCP Wait on Listener so you can fork the listener wire prior to starting to wait on it. I don't know of any way to interrupt TCP Open Connection - use a shorter timeout?
12-08-2012 07:58 PM
Thanks for the quick response.
I was hoping there was a more elegant Labview solution that may work for both the wait on listen and the connect VI.
I tried to close the wait on listener by closing the ref from the create listener.
That works. See attached picture. I use a queue to send the abort message. The wait on listen state will be blocked until either a connection is made or an abort message is sent via the queue. If a message is sent, the dequeue vi unblocks and causes the listener reference to close which will kill the wait on listen VI. If a TCP-IP connection is made it will close the queue reference which will kill the dequeue vi.
I guess for the TCP-IP connect VI I can:
A. Use a couple second time out that is tolerable to the operator if then abort the connection attempt. (like you suggested)
or
B. Create a VI with the TCP-IP Open Connection VI in it. I can launch that VI dynamically and wait until done (invoke node Run VI with Wait Until Done set to true). If a connection is made it will finish and I will read the outputs using an invoke node (Ctrl Val.Get). If it needs to be aborted, I will abort the VI using an invoke node (VI Abort).
12-08-2012 08:48 PM
One note about the code shown in your image: you're going to destroy the listener and set "Aborted" to True even if it doesn't time out. I'm not sure whether that's what you want. The reason is that destroying the queue will cause the Dequeue to stop waiting and return an error, but the Timeout output will be False. You should destroy the listener when you're done with it - it won't affect the TCP connection that the listener created - so in that respect it's OK, but you probably don't want Aborted to be True when the connection wasn't aborted. If you want to accept multiple connections on the same port you would leave the listener open, but it doesn't look like that's your goal here.
As for the TCP Connect, I can tell you that one of your approaches is a lot simpler than the other. If the operator is just going to abort it after what's effectively a shorter timeout period anyway, I can't see any advantage to the more complicated approach.