LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I programmatically determine the local port of a TCP connection that was opened using TCP Open Connection?

I have a remote system (non-PC) that is controlled via a TCP connection.  Once the TCP connection is established, the remote system sends data back to the PC via UDP to the same port number from which the TCP connection originated.  I've been controlling the system using two different applications.  One in C/C++ and the other in JAVA. It works pretty good.  Now I'd like to use LabVIEW.

 

So in LV how do I programmatically determine the local port of a TCP connection that was opened using TCP Open Connection?  I see TCP Listen and Create TCP Listener provide a way to specify the local port to listen on, but I can't see how to use that to my advantage being that I'm establishing the connection from LV, not listening for it.

 

I think I'm missing something.... any ideas?

 

Brian

XP/LV8.5
0 Kudos
Message 1 of 6
(4,473 Views)

Your design does not seem like a good idea in general. It most likely will not work across NAT, for example.

 

You could open the UDP connection first (which gives you the local port as output if the local ports was unwired), then open the TCP connection by wiring the output of the UDP open to the local port input of TCP open.

 

Of course there is no guarantee that the port will be available. 😉

 

Message 2 of 6
(4,471 Views)

Thanks!  That's what I was looking for.

Brian

XP/LV8.5
0 Kudos
Message 3 of 6
(4,461 Views)

However, I agree that for symmetry the TCP open function should return the local port the same was as UDP open currently does. In both cases this is an intersting output if the port is unwired or zero.

 

(Maybe I'll mention it in the monthly bug thread. If it's not considered a bug, I can create an idea later ;))

Message 4 of 6
(4,453 Views)

Hi altenbach,

 

Sorry for taking so long to reply to your latest post. I don't believe that the TCP Open not returning the port ID is a bug. This is currently the expected behaviour. Currently the only way TCP will return the port ID is with a Listen.vi or TCP Create Listener, like what bwharris has mentioned before. I would continue by submitting a product suggestion/idea Smiley Happy

 

To add to the content of this Discussion Forum, there is an example code written that may help you determine which ports are being used here: http://zone.ni.com/devzone/cda/epd/p/id/4591.

 

Jason L.

Product Support Engineer
National Instruments
0 Kudos
Message 5 of 6
(4,387 Views)

@Jason L wrote:

This is currently the expected behaviour.



Thanks Jason,

 

I don't think "expected behavior" is the right word though. In the first posts there is a clear scenario (albeit somewhat clumsy) where it would be needed.

 

It is more a "swiss cheese" situation, i.e. full of holes. 😄 UDP has it --- TCP doesn't --- which is inconsistent.

0 Kudos
Message 6 of 6
(4,382 Views)