LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

TCP IP Over Internet btwn Server VI and Multiple Client VIs

Hi there,

 

I want to write Server VI (located on PC at my location) to communicate with multiple Client VIs (front-ends to distributed applications).  I'm not sure what's the best approach and I know little about internet communications/addresses etc.

 

I've looked at the shipped TCP/IP examples but have been unable to communicate over internet even between different computers at our office.  I don't know what IP addresses to provide and what ports to use.

 

How would the Client VI's communicate remotely with Server VI?  Would the Client VI only need to know the IP Address of the computer running the Server VI?  Would I also need to nominate a Port?  Which Port numbers are guaranteed to be unused?  I have seen the list of registered port numbers.

 

I have installed the Simple Messaging Reference Library, is this the way to go?

 

Help is appreciated.

 

Battler.

 

 

0 Kudos
Message 1 of 7
(3,873 Views)

Your client's can use either the IP Address directly or the name of the server. The name is only available if you are running in effectively an enterprise network. Although Windows does provide some basic name services in a home/work group environment it is not always 100% reliable. If you are running in a corporate environment you should have name services available. There is a minor overhead to perform the name lookup but it is generally more reliable in a network that is using DHCP where a computer's IP address may change. The TCP VIs will accept either a name or an IP address.

 

You will need to chose a port number for the server. You should pick something at least greater than 1023. Everything below port 1024 is what are known as well known system ports. Ports 1024 through 49151 are user ports. You can pick a port in this range. Dynamic or private ports are 49152 through 65535. You would also be safe to pick a port number in this range. Prior to picking the port on your server make sure it is not already in use. You can determine this using the "netstat -a -p TCP" command at the command line. This will show you the ports currently in use on the machine. Once you choose your server's port number the client will need to use this port number and the server's IP address or name to establish a connection. The server will need to only specify the port number to listen.

 

If you want to be able to handle multiple client connections at one time the server will have to spawn a service task for each client connection. This can be accomplished by calling a reentrant VI dynamically. The server loop will essentially be a loop which will wait for a new connection. When one is established it will spawn the service task and then go back to listening for more connections. It is always a good idea for the server to keep track of the tasks it has spawned so it can kill then if it exits. Likewise the service tasks should notify the server task when it exits. This can be accomplished using queues, notifier or user events.



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 2 of 7
(3,868 Views)

Hello battler,

 

Look the examples provided by National Instruments.

 

Help-Find examples-Search-TCP/IP-Multiple Connections(Server/Client)

 

This example solve your query to communicate with multiple clients.

Thanks and Regards
Himanshu Goyal | LabVIEW Engineer- Power System Automation
Values that steer us ahead: Passion | Innovation | Ambition | Diligence | Teamwork
It Only gets BETTER!!!
0 Kudos
Message 3 of 7
(3,865 Views)

Thanks very much Mark 🙂

 


@Mark Yedinak wrote:

Your client's can use either the IP Address directly or the name of the server. The name is only available if you are running in effectively an enterprise network. Although Windows does provide some basic name services in a home/work group environment it is not always 100% reliable. If you are running in a corporate environment you should have name services available. There is a minor overhead to perform the name lookup but it is generally more reliable in a network that is using DHCP where a computer's IP address may change. The TCP VIs will accept either a name or an IP address.

 


The clients will be simple networked and non-networked PCs.  The server PC is at our office.  You mentioned I can use the IP address of our server PC.  Is that the IP address of the Ethernet adapter?  I've seen multiple IP addresses when I do IPCONFIG.  Will this IP address ever change?

 


@Mark Yedinak wrote:


 

You will need to chose a port number for the server. You should pick something at least greater than 1023. Everything below port 1024 is what are known as well known system ports. Ports 1024 through 49151 are user ports. You can pick a port in this range. Dynamic or private ports are 49152 through 65535. You would also be safe to pick a port number in this range. Prior to picking the port on your server make sure it is not already in use. You can determine this using the "netstat -a -p TCP" command at the command line. This will show you the ports currently in use on the machine. Once you choose your server's port number the client will need to use this port number and the server's IP address or name to establish a connection. The server will need to only specify the port number to listen.

 


 

Does it matter if the port number is used on the clients PC?  I can't check this..  Can I reserve ports with distributed application?  What happens if these ports are blocked on the client PCs by the firewall or virus protection etc.  Is this possible?

 

 

@Mark Yedinak wrote:

 

If you want to be able to handle multiple client connections at one time the server will have to spawn a service task for each client connection. This can be accomplished by calling a reentrant VI dynamically. The server loop will essentially be a loop which will wait for a new connection. When one is established it will spawn the service task and then go back to listening for more connections. It is always a good idea for the server to keep track of the tasks it has spawned so it can kill then if it exits. Likewise the service tasks should notify the server task when it exits. This can be accomplished using queues, notifier or user events.


Multiple client connections are necessary.  In practical terms what do you mean by "spawn a service task".  Is the reentrant service task a VI which maintains a separate connection with each of the connections?

 

Shall I use the TCP/IP VIs or can I use the STM toolkit?


Do you have an example of such an implementation?

 

 

 

0 Kudos
Message 4 of 7
(3,858 Views)

The clients will be simple networked and non-networked PCs. The server PC is at our office. You mentioned I can use the IP address of our server PC. Is that the IP address of the Ethernet adapter? I've seen multiple IP addresses when I do IPCONFIG. Will this IP address ever change?

 

Does it matter if the port number is used on the clients PC?  I can't check this..  Can I reserve ports with distributed application?  What happens if these ports are blocked on the client PCs by the firewall or virus protection etc.  Is this possible?

 

Multiple client connections are necessary.  In practical terms what do you mean by "spawn a service task".  Is the reentrant service task a VI which maintains a separate connection with each of the connections?

 

Shall I use the TCP/IP VIs or can I use the STM toolkit?


Do you have an example of such an implementation?

0 Kudos
Message 5 of 7
(3,850 Views)

1. Any PC on not on the network will not be able to communicate with the server. Everything must be on the network in order to communicate. I can't really say which address you will need to use. You will need to ask your IT people which address would be accessible by all of your clients. When you run the server though by default it will listen on all addresses. As to whether it will change or not it depends on your network configuration. If may or may not change. Again, you will need to ask your IT people.

 

2. The port number you choose is important on the server. It can be in use on the client. The client should dynamically pick the port number on its side of the connection. TCP connections are identify by the destination (server) IP address and port number along with the source's (client) IP address and port number. Generally it is best to allow the client to dynamically pick it's port number. The server port number is the important one to uniquely identify the service. There is a process to reserve port numbers through IANA but I am not sure how difficult or costly that it. Yes, the port can be blocked by a firewall so it will need to be opened at the appropriate places in the network to allow it to pass through. This again is dependent on the individual networks configurations.

 

3. The spawned task will have its own connection. The server's listener will establish a connection for each client. You will get a TCP reference for each connection. This will need to be passed to the spawned task.

 

4. I am not familiar with the STM toolkit. This can all be accomplished using the native TCP VIs.

 

I will have to see if I have a basic example. The examples that ship with LabVIEW will show you what you need to do. You may need to look at several examples. You will want to look at the TCP client/server examples as well as the examples for dynamically calling VIs. Combining these two concepts should get you the basic server.



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 6 of 7
(3,830 Views)

Not that it is necessarily what you will be doing but I think if you were to llok at the Network Queue class you will see examples of all of the concepts discussed in this thread.



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 7 of 7
(3,816 Views)