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