LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

RegisterTCPServer and ConnectToTCPServer

I deal mainly in the LabVIEW world, but I'm having to translate some CVI code (the server side) to LabVIEW, and I'm trying to understand one piece of the CVI code first.  In the server side, there is a call to RegisterTCPServer

 

    else if ((status = RegisterTCPServer (xxTCP_PORT, xxTCP_Callback, NULL)) < 0)

 

and on the client side there is a call to ConnectToTCPServer

 

   ConnectToTCPServer (TCPHandle, xxTCP_Port, "xxName", yyTCP_Callback)

 

The part that is unclear to me is that the client and server are on different computers, and the Client seems to specify a serverHostName (in this example, xxName), but the Server's call to RegisterTCPServer only has the Port number in common with the Client.  I'm thinking that since no serverHostName is specified, it would default to localhost.  So, why does the client (in this example) specify the serverHostName?  Is the port number sufficient for the server/client to find each other, or is there some CVI call I should be searching for in the (server) code that must be being called somewhere that named the server to the samething the client is looking for?

0 Kudos
Message 1 of 6
(3,856 Views)

As is clearly explained in the online help for the function, RegisterTCPServer

 

Registers your program as a valid TCP server and allows other applications to connect to it for network communication.

Clients attempting to connect to your program must use the same port number. Thereafter, all requests by the client are routed through the specified server callback function. You can register your program as a TCP server multiple times as long as you specify different port numbers.

 

On the server side you do not need the host name simply because you are the host!

 

On the contrary, on the client side you need to know the server name (together with the port number) so that your messages are properly routed to the correct machine: it could be the same machine or a different PC over the network.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 6
(3,852 Views)

Hi mrbean,

 

You can simply pass the server's IP address as "xxName".

 

For this function to connect to the server, the server must have been created beforehand.

RegisterTCPServer function serves that purpose. It opens a port and waits for connections.

 

ConnectToTCPServer connects to the server when supplied with correct machine and port identifiers.

 

Hope everything is clear now.

S. Eren BALCI
IMESTEK
0 Kudos
Message 3 of 6
(3,848 Views)

all good things come in threes - so just let me add that CVI provides some examples, too. You may use the example finder 'Help / Find Examples' and search for TCP Smiley Wink

0 Kudos
Message 4 of 6
(3,845 Views)

Ok...what is confusing me is that I don't see anywhere that the server says his hostName is (in this example) "xxName".  So why does the client specify this?  How does he even know to use this name?  I haven't done too much with TCP/IP, so I'm trying to understand.  It seems like on websites, the server's name is espn.com, or yahoo.com, and the port number is 80 (for www).  How do clients to MY server know how to refer to it? 

 

Also, I will have TWO clients talking to this one server.  One will be using the ConnectToTCPServer. as I'm re-using this portion of the CVI code.  However, the other client(s) will be LabVIEW tests (called one by one from a TestStand sequence file) that open a connection, send a message, wait for a response, and close the connection.  I mention this just to know if (from the labVIEW side) I need to be consistent in the way I refer to the server (besides its port number).

0 Kudos
Message 5 of 6
(3,834 Views)

The server name is either the machine name or its IP address, so it's not the server that "declares" a name.

Your client must know both the server name and the port to connect to, as there may be several servers listening to the same port on your network (so you could ideally talk to any one of them), but you want to connect to one specific machine. These are configuration parameters that must be established out of the application: there can be a network administrator that assigns machine names / IP addresses and decides which ports to use, and your program must adapt to these elements. When I have to deal with TCP communication normally I store server name and port on a configuration file that my program reads at startup, before establishing the communication.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 6 of 6
(3,831 Views)