LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

TCPIP Connection and event structure

Hello everyone,

 

i want to creat a connection  through TCPIP to write and read messages. i have different messages to write so i did the writing of each message using an event structure. Since i am new to labview there are some questions i have.

 

attached above is my TCPIP sender and server.

 

1) do i have to place the TCP Open Connection  in the event structure for each button, that means openning a new connection  every time i click on an event case  (BT1,BT2,BT3) or is it preferable to open the connection only once as i did.i observed that when putting the tcp open connection in every event case  (BT1,BT2,BT3) only the first event i click works the rest only sents me an error mail when clicked.

2) for every connection i open do i have to close  after my message has been sent? forexample if i click on my  BT1 do i have to close the connection. befrore reopenning when i have to send my second message in my BT2 event case?

i will be every happy to have answers to my questions 🙂

Download All
0 Kudos
Message 1 of 3
(787 Views)

1) Not if you open the connection before going into the while loop where the event structure is placed. That is, of course, given that you don't open connections to multiple different IPs.

2) No. It's not good to open and close connections every time as you need a local port to do that which isn't immediately released after close, but is held "in custody" by the system for some time so that, depending on the number of open/close actions going on per second, you might run out of local ports. The only solution would be to find a free local port and to use the same one over and over, but that's not the default in the TCP Open VI.

0 Kudos
Message 2 of 3
(767 Views)

I haven't looked at your code, because (from your question) it sounds to me like you are making the classic mistake of worrying about "How" you code something before considering "What" you want to do.

 

I'm guessing that the "What" can be paraphrased as the following:

  • I have a computer that generates data which needs to be sent to a (single) different computer for processing, along with some "instructions" on how, or maybe what, to process.
  • I want to generate a program that will (a) organize my data, (b) establish connection with the remote "processing" computer, (c) send data + instruction "packages" for remote processing, and (d) close the connection when I am done.

If the above scenario is accurate, and you know the "protocol" of the remote computer (and it is compatible with the model I'm proposing), you would do the following:

  1. "Reach out" to the Remote machine, establish a TCP/IP connection, and initialize (according to the protocol for the remote service you want) access to the service you need.
  2. Start generating "Requests" in whatever format of Instructions + Data the remote procedure requires, sending TCP/IP packets as instructed.
  3. When you are finished, send the TCP/IP packet that informs the remote procedure that you are finished, and close the TCP/IP connection.

Bob Schor

0 Kudos
Message 3 of 3
(765 Views)