WebServer, .flush() or delay(1)?

Hi,

I have a little web server running on an Arduino Ethernet. The code is based on this example:

It is running fine. I am just wondering about this part of the example code:

EthernetClient client = server.available();

// Lots of code to send data

// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();

I'm wondering, if using the EthernetClient.flush() method wouldn't be a better and cleaner approach:

EthernetClient client = server.available();

// Lots of code to send data

// give the web browser time to receive the data
client.flush();
// close the connection:
client.stop();

Any opinions here?

Regards,
Christian

  1. There is no need for the delay(1) - it does no ggod and cannot possibly do what the comment says.

  2. client.stop()/close connection should contain the flush IF IT IS REQUIRED. You should do be using flush at all!

  3. The server should be normally close the connection - the server is the slave and the client is the master!

Forget that flush exists!

Mark

Older versions of the library had this problems. Use Ethernet 2.00

@holmes4:

1:
TCP connections check for proper reception of the data packets. So if the server closes communication before packets are received, there might be problems. Also note that communication is handled by the WIZNet W5100, not the ATMega. Data packets might still be sent, while the ATMega is already continuing code execution. Calling stop() too earlymight stop the W5100 in it's tracks.
But I don't know enough about the W5100 to be sure, hence my question.

2:
I checked the library code. flush() is not implemented (It has a //TODO as code :o ). stop() seems not to include any code to wait for completion of transmission.

3:
In the code the EthernetClient client is an object generated by the server whenever an external client connects. The client object handles the communication of the Arduino with that external client.

@Juraj:

I don't have problems. I'm trying to understand the example and improve my code.
With Ethernet 2.00, are you referring to Ethernet2:

That's the only other Ethernet library I could find, and it's only suitable with the W5500 chip, not the W5100.
Unfortunately it also doesn't have a working flush().

the ‘old’ Ethernet library has a 2.00 update published last week