11-05-2009 12:16 PM
I'm experimenting with the network queue example found in C:\Program Files\National Instruments\LabVIEW 2009\examples\general\queue.llb\Network Queue Example. In the server, a TCP Open Connection occurs at localhost:NetQueueData. The server also does a TCP Listen at NetQueueEnd:8155. The Client does (more or less) the oppposite. It opens a connection to localhost:NetQueueEnd and listens on NetQueueData:8154. The problem I have is the comment found in the client....
"The listener must start first in the Server before this VI opens the connection. This delay makes sure this happens."
I have a Server (of sorts) that is always running. The clients, however, are going to come and go. What I mean is that I plan to kick off the server (from TestStand) in its own thread. Then teststand will call test VIs one by one. Each (when it's running) will be the client. I would like each client to (as described above) connect to localhost:NetQueueEnd and listen on NetQueueData:8154. It will send a command to the server, the server (listening on 8155) performs the client command and replies to the client who receives on 8154. The client determines pass/fail and tells TestStand. Then TS calls the next (client) and we repeat the above sequence.
Is there any chicken/egg problems with trying to establish a listener at the client AFTER the server has already established the TCP connection? Any other concerns with what I'm proposing?
11-05-2009 10:43 PM - edited 11-05-2009 10:47 PM
I must admit I'm a little confused by your question, but the words Network Queue reminded me that I had worked on an example library of VIs that operate almost exactly like the queue functions themselves, but that can send and receive data over the network.
You might give these a try (saved in LV2009). You simply host your queue using the Server polymorphic functions, and use the Client polymorphic functions to access them across the network. There is built-in support for three datatypes: string, variant, and object (LVOOP).
You might give these a try. It's about as simple as using named queues (hopefully 🙂 ).
11-06-2009 11:40 AM
I basically have two VIs running. One is a client, one is a server, although it can be argued that both are servers and both are clients. One gets the title of Server, though, because he's always running, and the client runs for a bit, sends a message to the server, gets a reply, and is done. Then another client does the same thing, all controlled by TestStand.
My problem, though is that I TCP_Listen at the server for the Client's TCP message and I TCP_Listen at the client for the Server message. However, what I'm seeing is that the listen has to happen before the TCP Connection (associated with that Listen) is created. How do I get this to work? Does the Network Queue (OO version) do anything differently?
11-06-2009 03:13 PM
11-06-2009 03:56 PM
mrbean wrote:My problem, though is that I TCP_Listen at the server for the Client's TCP message and I TCP_Listen at the client for the Server message. However, what I'm seeing is that the listen has to happen before the TCP Connection (associated with that Listen) is created.
Why does your client need to listen to the server? TCP packets go both directions, so there shouldn't be a need to establish two different connections between the same two programs.
11-06-2009 04:16 PM
This is correct. You can simply transmit in both directions on one TCP communication line if you like.
When I have established bidirectional communication schemes in the past, where each side creates a listener, I would include a handshaking step. Even though both sides have a listener, one is still considered the server. First the client creates its own listener. Then the client connects to the server. After that connection is successfully established, the server connects back to the client.
11-06-2009 04:52 PM
I agree with Nathan; I see no need for two connections.
A TCP connection is just like a telephone connection: Somebody has to dial the phone, and somebody else has to have their ringer turned on.
After the connection is made, the two ends are equals; who talks and who listens is up to you - they can both transmit and they can both receive.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
11-06-2009 05:11 PM
11-07-2009 08:59 AM
I have yet another question about the example in C:\Program Files\National Instruments\LabVIEW 2009\examples\general\queue.llb\Network Queue Example. It's really more of a general question but it's easier to point to this example for reference.
In this example, the the two TCP Open Connection calls (one in Client, one in Server) set up the connection using 'loclhost' for the address then they provide a service name instead of a specific port. This makes perfect sense - almost. If you specify a service name, LabVIEW queries the NI Service Locator for the port number that the server registered. However, the only way to register a port number is to call a TCP Listen. I did find that if you go to the Tools::Options::VI Server, you can uncheck the "Use default" in the 'Protocols' TCP/IP area, and you can specify ONE port and service name. Is there a way to create multiple port/servicename associations. Otherwise, I don't see how you reliably create TCP Connections within localhost and a specific port. It seems like there is a possibility of selecting a port that is used already. I get Error 63 when I try. In other parts of my code I successfully create TCP/IP connects to specific IP addresses (non-localhost) but I can't get this localhost thing to work.