LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ClientTCPRead timeout doesn't seem to work

Maybe I don't understand how the call is supposed to work, but I'd expect this line of code:

 

rc = ClientTCPRead(g_hconversation, p, n, d);

 where n = 5000 and d = 20000, to sit in a read until either:

 

- 5000 characters are read, or

- the 20-second (20,000 milliseconds) timeout occurs.

 

But it's not doing this. I'm getting about a 3/4 full buffer and it's returning much, much faster.

 

Can anyone shed some light on this for me?

 

Thanks.

0 Kudos
Message 1 of 9
(3,980 Views)

I don't know why you reached the conclusion that the function should wait for 5000 characters... Note that I have not used this function myself, but from the help I'd conclude that

 

n is the maximum number of characters to read (i.e. the max buffer size)

 

It also says, that the function waits until some data is available at the port, and that its return value is the number of bytes actually read.

 

So the function returns not later than 20 seconds and reading not more than 5000 characters, this is exactly what you observe Smiley Wink

0 Kudos
Message 2 of 9
(3,972 Views)

I'm sorry, but that just doesn't make sense. TCP is a streaming protocol. There's no way to know when the sender is finished, so I'd expect the read function to continue to read until it runs out of space or time. Otherwise, what criteria does it use to stop reading and return?

 

I may be missing something, but that just seems really odd. Perhaps I should stick with winsock. Do you happen to know if there's anything preventing me from using winsock in a CVI application? How do I direct the build utility to the right library?

 

Thanks for the reply.

0 Kudos
Message 3 of 9
(3,962 Views)

@mzimmers wrote:

I'm sorry, but that just doesn't make sense.



As I said I haven't used this function myself, so let's hope that a more experienced user will assist...

 

Searching the forum I have found this link and also I had a look at the example program client.cws. It seems that this function works in a callback only... did you try it this way?

0 Kudos
Message 4 of 9
(3,960 Views)

OK, thanks, Wolfgang. Maybe in the meantime, I'll do some experimentation. Can you tell me how to point the builder to a library? Does the builder use the PATH variable, or is there a setting somewhere for non-CVI libraries?

0 Kudos
Message 5 of 9
(3,957 Views)

Thanks for the update, Wolfgang. My current implementation uses the call both within a callback, and otherwise. I guess I'll have to eliminate the "otherwise."

 

Can you give me some direction on how to include a library like ws2_32.lib into my executable?

 

Thanks again.

0 Kudos
Message 6 of 9
(3,945 Views)

you need to include it (and the corresponding include file) in your project: Edit / Add Files to Project.

Message 7 of 9
(3,942 Views)

Adding a library to a project is simply made by Edit  >> Add files to project menu item; you will need to add the corresponding include file to the source files where you are accessing library functions.

 

But in my opinion I'll give another try to TCP library functions. I suggest you take a look at \samples\tcp\message.cws example which shows in MessageReader project how to deal with reading data (see TCPCallback function). As of my experience, TCP reads normally returns the exact number of bytes requested, but it is to be said that I normally structure my application to handle very short messages (less that 200 bytes/message) using shorter timeouts.Nevertheless, both the example I pointed you to and the help for ClientTCPRead show you how to loop and accumulate data until all message has been read.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 8 of 9
(3,936 Views)

Roberto: I looked at that sample. it seems pretty similar to what I am trying to do.

 

I think maybe I am guilty of taking too literally the caution about not doing too much processing within a callback. My intended design was to read the data in the callback, then post a deferred task to process and plot the data. The problem is, without processing it, there's no way for the callback to know when the server has finished sending.

 

So, I think maybe the best approach here is simply for me to allow the callback to do all the work. At least this way, I can read and process at the same time, so I'll know when the server's finished sending.

 

BTW: from the help on ClientTCPRead:

 

Return Value

Name Type Description
status int Return value indicating whether the function was successful. Unless otherwise stated, zero represents successful execution and a negative number represents the error code.

 


I'm not sure what they means by "otherwise stated," but...the return value is either the number of characters read, or an error code. I've yet to witness this function return a 0. Is this possibly an error in the docs?

 

Thanks for the help...talking this through helps clarify issues for me.

0 Kudos
Message 9 of 9
(3,932 Views)