Client.flush(); TCP

Hi again,
My latest problem concerns the “client.flush” function. It’s obviously very useful to make sure the right TCP packets are being recieved but I’m having “overloading” errors with it.

Here is the relavant fragment of code:

if (client.connected()) {
while (client.available()) {
f = client.read();
delay(100);
Serial.println("The Incoming Byte is: ");
Serial.print(f);
client.flush();
delay(1000);
if(f = 1){
char x;
x = client.read();
Serial.println("Value is: ");
Serial.print(x);
Serial.println(“Value printed once”);
client.flush;
}
else if(f = 2){
char y;
y = client.read();
Serial.println("Value is: ");
Serial.print(y);
Serial.println("Value is: ");
Serial.print(y);
Serial.println(“Value printed twice”);
client.flush;
}
}

If I comment out the client flush functions it compiles fine but I’d rather have them there in case my sender is faulty.

Thanks for any help or suggestions

Hi @OddieCAT

Client.flush() is method and so you have to use the function call syntax with () at the end. Two of your calls are not like this. Change client.flush; to client.flush();

I would also like to point out that this is not a reliable method of handling the returned data from a web server since client.flush() only flushes the TCPClient object buffer but does not flush any packets from the TI CC3000 that may still be coming in.

It is much better in my experience to have two while loops with timeouts: a first loop to wait for client.available() and a second loop to read the data. This is much more reliable. You can find my examples if you search around a bit.

1 Like