LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to send more then one data via tcp

Solved!
Go to solution

yeah i know

but he told me to do only one of his examples

and i did the first one at client

but i will try do the second one at server too

let's see if i have sucess!

0 Kudos
Message 21 of 43
(1,288 Views)
Solution
Accepted by EduU
If you're going to multiply the length by 4, then you need to remove the false constant wired to "prepend array or string size" in the server ONLY so that you will still be sending the array length.  Somehow the first 4 bytes of the string you send must contain a length, so that the client knows how much more data to read after that.  You can either do this by sending the actual length of the string, or you can send the array length (letting flatten to string handle it) and then multiplying by the size of your data type, but you must do one or the other.  Right now you're not sending any length at all, and since the first piece of data is a 0, it's being read as the length and then you're not reading any further data.
Message 22 of 43
(1,287 Views)

Hi nathand,

why do you need to multiply the length with 4? If you convert the data to a string and put the length of the string before it, then you have the size you really send.

 

Mike

0 Kudos
Message 23 of 43
(1,283 Views)

could you share with me your code nathand?

i really don't understand what you are talking about

i already did the prepend array on server, removed the false constant, multiply by 4 the client..

but nothing worked x(

 

so if you could share it with me

i would appreciated!

 

thanks

0 Kudos
Message 24 of 43
(1,278 Views)

Hi,

as i wrote before, to send tcp data and to read it, i every time use the code from the attached picture. You can convert every data you want to send to string. Sometimes you have to try out if you need to insert the array size or not, but normally i have no problems with it.

 

Hope it helps.

Mike

0 Kudos
Message 25 of 43
(1,278 Views)

You can't mix and match the way are doing things.

 

You need to think logically about what data you are sending.

 

At the Server.

1.  I will send 4 bytes that tell how long the data is.

2.  I will send that many data bytes.

 

At the client.

1.  I will read the first 4 bytes so I know how much more data to read.

2.  I will read that many more bytes.

 

If you leave out anyone of these steps on either side, then obviously the communication won't work.

 

There are two ways of sending the amount of data in step #1.

 

1.  The number of bytes.  How many bytes (essentially U8) is in the message string.  This is the way the string length method works.  You DON'T prepend array here.  You MUST explicitly put in the front of the data string how many bytes are going to follow.

2.  The number of elements in the array.  When you preprend array size, this is the method that is automatically happening for you.  Let's say the array has 10 elements of single.  That is 4 bytes per element.  So on the receiving end, you need to take the 10 you get out and multiply it by 4 so that you read the next 40 bytes.

Message 26 of 43
(1,281 Views)

ok raven but i still have problems

i know what you wrote is correct

but i can't figure it out

so i wanna ask

can someone send me the codes for server and client?

so i can see it

and discover what are u guys talking about!

if nathand or raven could do that

i will appreciate!

 

thanks

0 Kudos
Message 27 of 43
(1,264 Views)

Hi EduU,

see the attached files. Both are LV8.6.

 

Mike

Download All
0 Kudos
Message 28 of 43
(1,262 Views)

well guys now i think it's working

but it have some delay, this is normal?

i change the amostragem on server... and 30 seconds after or something the client change

i will upload the codes now

so you can check for any error!

Download All
0 Kudos
Message 29 of 43
(1,259 Views)

lol guys it was my fault.. the server was lagging because i was using highligh and probe now i turned it off

and works perfectly =D

 

thanks for Mike, Nathand and Raven!

 

now a doubt, if i want to connect the client in this server in another pc... what change i have to do?

only chage the ip at server vi.. and then put this ip in "adress" of client vi?

0 Kudos
Message 30 of 43
(1,249 Views)