LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ClientTCPRead return value

hey

i am building a tcp client, i used ConnectToTCPServer with a callback- which fires periodically so i used ProcessTCPEvents in an loop on every read.

the server accepts AT commands and responds accordingly-

to reduce the chance that  i will read upon my next ClientTCPRead a message that was sent after a timeout i first clear the buffer

e.g:

I send A

the server didn’t respond in a timely fashion

 I get a timeout error (pass it on to the user)

in the meanwhile the server sends B as response to A, (no ProcessTCPEvents is yet to be executed because no write is done).

I try to write C ,fire ProcessTCPEvents and then read B and D- C’s reponse).

I want to read only D so I need to somehow clear old messages.

 

Code to clear the buffer:

while(1){
            G_Connection_Error=ClientTCPRead (G_handle, G_Receive_Buf, BUFFER_SIZE, G_timeout);//flush tcp buffer stack
            if(G_Connection_Error>0) OutputToText_ep_printToTextBoxColor(RED,"out of order message: %s.\n",G_Receive_Buf);
            else break;
}

 

number of questions:

1. what does a 0 return value means- there is a 0 byte message-can there be a situation where ClientTCPRead returns 0

2. is there a better way to flush the tcp buffer

3. is there a way to ensure that on every message the callbak func will be fired without the ProcessTCPEvents

 

Thanks in advance

 

Moshe  

0 Kudos
Message 1 of 4
(3,110 Views)

Hello Moshe,

 

1. ClientTCPRead Return indicates whether the function was successful. Unless otherwise stated, zero represents successful execution and a negative number represents the error code.

2. I believe you are doing it the right way.

3. That is the correct function to call

 

Regards,

0 Kudos
Message 2 of 4
(3,092 Views)

thanks

a follow up for the first answer:

ClientTCPRead  returns the number of bytes read, if the returned value is zero what does it mean?

if no data was read  the returned value should be a timeout (-11), if data was read the return value must be larger than zero

and thus i ask what does a return value of zero mean?

 

BR

Moshe

0 Kudos
Message 3 of 4
(3,080 Views)

If you pass a 0 for the data buffer size, then ClientTCPRead would return 0. But otherwise, it should return non-zero values.

0 Kudos
Message 4 of 4
(3,069 Views)