LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to determine TCP/UDP port# assigned when zero is specified?

I have passed a zero to the port input of UDP open or TCP Create Listner to specify the next available port. How do I determine the port assigned by the system? I DO need to know this for the higher level protocol that I am building.
0 Kudos
Message 1 of 2
(2,849 Views)
Hi,
you might be able to use netstat, which is built into windows. Try a call to "netstat -a" through the System Exec.vi, then create your connection, and then call "netstat -a" again, and compare the outputs.It means a bit of string manipulation, but the output is highly structured, so this shouldn't be too bad.
Worth a try. I have it working with UDP - just adding in the data manipulation - will post it here in a little while.
Curious though - every time I create a UDP connection, I also get a TCP connection into the bargain!

S.
btw, the help for netstat is as follows :

C:\WINDOWS\TEMP>netstat help

Displays protocol statistics and current TCP/IP network connections.

NETSTAT [-a] [-e] [-n] [-s] [-p proto] [-r] [interval]

-a Di
splays all connections and listening ports.
-e Displays Ethernet statistics. This may be combined with the -s
option.
-n Displays addresses and port numbers in numerical form.
-p proto Shows connections for the protocol specified by proto; proto
may be TCP or UDP. If used with the -s option to display
per-protocol statistics, proto may be TCP, UDP, or IP.
-r Displays the routing table.
-s Displays per-protocol statistics. By default, statistics are
shown for TCP, UDP and IP; the -p option may be used to specify
a subset of the default.
interval Redisplays selected statistics, pausing interval seconds
between each display. Press CTRL+C to stop redisplaying
statistics. If omitted, netstat will print the current
configuration information once.
// it takes almost no time to rate an answer Smiley Wink
0 Kudos
Message 2 of 2
(2,849 Views)