10-08-2018 02:32 AM
Hi All,
I have modified a TCP Bidirectional example, I received from one of the forum question. I have an external client which listens to a port 62000 and sends variable string as Byte array to my TCP server. Since I am new to Labview, I cannot manage to handle the data while using TCP Read. I always get an Error 56 because of it. Only if I send the correct length of the String, I then do not get error. Could anyone please help me how to manage TCP Read for variable strings? I am attaching my .VI for your help.
Thanks and best regards!
RG
Solved! Go to Solution.
10-08-2018 02:59 AM
Hi,
as I can see, you are sending the number of bytes (or string length) at first. But why are you reading 512 byte? You have to read 4 byte (I32) first and then the number of bytes represented in the first 4 byte value.
Regards
Kay
10-08-2018 03:10 AM
Hi Kay,
Thanks for an immediate response. What exactly do you mean by "and then the number of bytes represented in the first 4 byte value" ?
If send 4 bytes at first TCP read, I get the string length as 4 and my indicator Solvay String only reads 4 character at a time. I need to get the whole string ? What should I change?
Thanks
RG
10-08-2018 04:47 AM
Please have a look at the example "Multiple TCP Connections" in your LabVIEW IDE "Find Example".
The idea is to append the string length as a I32 value at the begining of the string, and send it over TCP. To read the correct length of the original string, you first have to read 4 bytes (I32) (string lenght) and then the remaining number of bytes.
Otherwise you could retain an error 56, because it is "just" a timeout and it shows that the connection is still alive.
Regards
Kay
10-08-2018 06:00 AM
@erraunakgupta wrote:
I get the string length as 4 and my indicator Solvay String only reads 4 character at a time. I need to get the whole string ? What should I change?
First you read 4 bytes. Cast that into an I32. Those first 4 bytes you just read is the length of the rest of your message. So you do a second read with that value to get the data you care about. Use the protocol!