LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

tcp read

dear sir,
            All tcp labview example program contains tcp read has 4 bytes,I dont understand why they specifically give it 4 byte;anyone pls explain me briefly.
 
Thanks and regards
Jayanthi.k
              
0 Kudos
Message 1 of 3
(2,668 Views)
Hello,
I took a look at the Data Generator/Data Receiver example and I found that only the first read in the Receiver is 4 byte long: this is needed purposely to receive a long value (I32) that specifies the data length of the subsequent read.
In any case, they are just examples: feel free to wire any value your application needs.

Regards
Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 2 of 3
(2,662 Views)

To expand on the explanation which was given - the TCP functions do not have something like the termination character you would find in the serial function, so you have to know how many bytes to read in advance.

To do this, a simple mechanism is used - before data is sent, the length of the string is checked (this produces an I32 number, which is 4 bytes) and that length is sent before the actual data. On the receiving side, you always know to check for that length first and you use the result to know how many bytes to read.

Other implementations might include reading a fixed number of bytes and relying on timeout errors or reading one byte at a time until you find a termination character, but this method is usually better.


___________________
Try to take over the world!
0 Kudos
Message 3 of 3
(2,656 Views)