LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to handle variable Byte Array (or String) in TCP Read protocol

Solved!
Go to solution

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

0 Kudos
Message 1 of 5
(2,662 Views)

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

0 Kudos
Message 2 of 5
(2,655 Views)

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

0 Kudos
Message 3 of 5
(2,649 Views)
Solution
Accepted by topic author erraunakgupta

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

0 Kudos
Message 4 of 5
(2,623 Views)
Solution
Accepted by topic author erraunakgupta

@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!


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 5
(2,615 Views)