Search code examples
network-programminglabview

How do I implement a labview server and client to send and receive network packets in parallel?


I am writing two programs (server.vi) and (client.vi). that communicate with each other over a TCP connection.

After the client opens a TCP connection with the server, the server responds with a packet of type "A". The client sends another packet of type "A" back to the server as an acknowledgement. At this point the server starts sending a continous stream of packets of type "B" to the client. And the client starts sending a continous stream of packets with type "C".

This means the sending an receiving of packets with types B and C will be in parallel.

How should I implement something like this in labview?

Here is one idea i have and I was hoping someone could either comment or provide a better suggestion.

  1. the server has two while loops

    a. first while loop consists of a TCP read function that receives packets of type "C".

    b. second while loop consists of a TCP write function that sends packets of type "B"

  2. the client has two while loops

    a. first while loop consists of a TCP write function that sends packets of type "C"

    b. second while loop consists of a TCP read function that receives packets of type "B".

This way we are sending and receiving packets of type "B" and "C" in parallel.

All the while loops are independent of each other and are essentially infinite unless both client and server programs are stopped.

Does this make any sense? Is there a more clever / better aproach to doing this?


Solution

  • That sounds like the appropriate way to have two processes run in parallel in LabVIEW, yes.

    Have a look at the examples that come with LabVIEW - in LV 2012 there's a 'TCP Communicator - Active.vi' (Help->Find Examples->Networking->TCP & UDP) that looks like it does something similar to what you're describing.

    You need to figure out when and how to stop each loop - the example above uses a local variable but you could also do it with a notifier, for example.