LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best Method For Communication With Executable

Is there a way to see what TCP ports are open?

0 Kudos
Message 11 of 15
(863 Views)

What exactly are you looking for? If you simply want to see what is currently in use on the PC you can type "netstat -a" at the command line. If you are connecting to a server on some well known port and you are asking about your local port use the default port of 0 and let the OS pick it for you. If you are trying to pick one to use for a server you are writing you are usually pretty safe picking a high number port.

 

Here is a blurb from the IANA regarding port numbers:

 

(last updated 2011-01-14)

The port numbers are divided into three ranges: the Well Known Ports,
the Registered Ports, and the Dynamic and/or Private Ports.

The Well Known Ports are those from 0 through 1023.

DCCP Well Known ports SHOULD NOT be used without IANA registration.
The registration procedure is defined in [RFC4340], Section 19.9.

The Registered Ports are those from 1024 through 49151

DCCP Registered ports SHOULD NOT be used without IANA registration.
The registration procedure is defined in [RFC4340], Section 19.9.

The Dynamic and/or Private Ports are those from 49152 through 65535

A value of 0 in the port numbers registry below indicates that no port
has been allocated.


Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 12 of 15
(851 Views)

 


@amaglio wrote:

Thanks for your input Mark, it is much appreciated. When using TCP can there be multiple lines of communication going at the same time. For example, lets say I have a TCP server executable that may communicate with X number of TCP client executables. Can this TCP server executable open multiple TCP connections to numerous TCP client executables? If so, what is the best way to do this... Should I just increment the port number or does this have to be 6342? Thanks for you help


 

By definition a server does not open a connection to a client. The client establishes the connection with the server. And yes, a server can have multiple connections open at one time. Your server would have to listen for incoming connections and when one comes in it would spawn a separate task to service that connection. Your server would always be listening on a single designated port number. When the client establishes a connection it would allow the OS to pick its local port. The only thing this port is used for is to aloow the connection to be uniquely identified. That is why you allow the OS to pick it. It will always give you an available port number.

 

If you do write your server to allow multiple connections it is always a good idea for it to keep track of all the tasks it spawns so that if a user closes the server it can cleanup after itself and terminate the running tasks. This will prevent zombie processes from being left on the system.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 13 of 15
(850 Views)

Okay, after reading your post and experimenting a bit I think I get the idea. So a server for example would start up first using maybe the TCP Listen.vi and if I wire a 0 to the port number Windows will dynamically choose a port for me. So far so good. Now, I can see what the port number that Windows selected is. So if my clients want to connect to the server they will use TCP Open Connection.vi using the port number that windows obtained for me. Now this must be where the local port number comes into play... So I can have the clients connect to the server using the same port number, and if I leave the local port number windows will again dynamically assign me one? Now even though each client used the same port, they have different local ports, so does the server have a separate line of communication with each client? Thanks again 

0 Kudos
Message 14 of 15
(831 Views)

No, your server should ALWAYS use a predetermined port number. If you use a random port your client will not know what port to connect to. You are correct though, your server will create a TCP listener and wait on that until a client connects. Your client will use the server's port number to establish a connection. However on the TCP Open VI there is an option to specify the client's local port. This is the port you should leave set to 0 allowing the OS to choose an available port.

 

Each TCP connection is uniquely identified using the server's and client's IP address as well as the server's port (needs to be predetermined so client's know what port to connect to) and the client's local port which is generally chosen randomly. So, even if two client's on the same machine connect to a server their connections will be unique since they will be using different local port numbers.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 15 of 15
(827 Views)