Jump to content

which size to choose for data reading


Recommended Posts

hello

i'm new here, i would like to ask you what to do if i write datas with the TCP write component to a server.

this server answers me with a message that i don't know the number of bytes that are sent before my read operation.

so for reading its answer i dont know which quantity choose for the size parameter of the TCP read.

if this number is too few, i will receive only the begining of the datas.

if this number is too large, i receive datas which don't correspond with the answer + the normal message.

in fact i would like to know the exact size of datas to read.

thanks

(ps: i use labview 7.1 and sorry for my poor english)

Link to comment

That depends on how your server works. I assume you can't control it, so what you will need to do is one of the following.

The first solution would be to ask for a large number of bytes (larger than the longest message you can get) and set a long enough timeout, but you say this won't work because the server sends additional data.

In that case, you will need to know what you're getting from the server.

Either you will need to know when you send the command in what format the server will send the answer (and then you ask for a different number of bytes each time) or you will need to be able to recognize the end of the answer and then you ask for a single byte each time until you can identify that you got the message correctly.

Of course, if the server sends the length of the data in advance (as is common in LV implementations) then all you need to is read that part of the answer and then you will know how much to read.

Note that in any case you will probably need to handle error 56 seperately for the loop because it will have different meanings depending on what you're doing.

Link to comment

thank you for your help

my problem is that i send /POST and /GET queries and the answers have different sizes and can be ended either by different ways, either CRLF (in the middle of the message CRLF can appear several times whithout ending the message but just to separate datas) or simply an alphabetic character or a number (but a string) etc....

i feel it is going to be difficult to solve.

Link to comment

I find it surprising that the server would send other data on your connection. Normally, a server can talk to many clients by creating a seperate "channel" for each client. If that's the case, then all you need to (presumably) is display the data to the user.

In any case, I would expect that there should be some way of knowing either the length or the end of the message. In your other post you mentioned this is a chat server. How do other clients know when the messages are over?

Also, do you have the protocol the messages are sent in and did you look at the traffic to see if you can identify either a length or a termination char?

Link to comment
  • 3 weeks later...
It seems that in this case gamez does not control the server, so that is probably not an option.

That's right and the fact that CRLF is used as message terminator but can also appear in the message itself makes it a bit complicated. However there has to be some specific protocol specification.

Either you read in one line and from there can know what will have to follow if any (so your receive loop already needs to know about the specific protocol) or you have an empty line added to the end of every multiline message, which will indicate an end of message.

Rolf Kalbermatter

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.