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 =;
Serial.println("The Incoming Byte is: ");
if(f = 1){
char x;
x =;
Serial.println("Value is: ");
Serial.println(“Value printed once”);
else if(f = 2){
char y;
y =;
Serial.println("Value is: ");
Serial.println("Value is: ");
Serial.println(“Value printed twice”);

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