Sending Data to an EthernetClient.

I looking at the code to create a server response from a client HTTP request.

My question is: at what point is the data sent from the server to the client.? Is it on the "client.stop();" command?

          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
		  client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println("Hello World!");
          client.println("</html>");
          client.stop();

Thanks for your time,
Harold Clements

It's not documented, but I think in practice that each call to print(), println(), write() results in a separate packet being sent, so the response will be transmitted incrementally as you output it.

Thank you very much for your reply. I ruled at out as I was expecting to have to define the size of the message in the header, (despite the fact that the code I posted does not do this!) and send it in one burst...

As I say, thank you for answering my question...
Harold Clements

If you want to bundle up the html code into one print statement you can send it like below. I don't have a packet sniffer, but the below method may place much more of the data sent into a single packet.

            client.print(F("<HTML><HEAD><TITLE>Zoomkat's frame refresh test</TITLE></HEAD>"
            "Zoomkat's Arduino frame meta refresh test 8/17/13"
            "

Arduino analog input data frame:
"
            "&nbsp;&nbsp;<a href='/datastart' target='DataBox' title=''yy''>META-REFRESH</a>"
            "&nbsp;&nbsp;&nbsp;&nbsp;<a href='/data' target='DataBox' title=''xx''>SINGLE-STOP</a>"
            "&nbsp;&nbsp;&nbsp;&nbsp;<a href='/datafast' target='DataBox' title=''zz''>FAST-DATA</a>
"
            "<iframe src='/data' width='350' height='250' name='DataBox'>"
            "</iframe>
</HTML>"));

haroldjclements:
I ruled at out as I was expecting to have to define the size of the message in the header, (despite the fact that the code I posted does not do this!) and send it in one burst...

I'm not sure whether this is still an issue for you, but if you needed to calculate the length of the response before sending it then you could print the response to a char array in memory and then measure the total length before sending it. This would be easy enough to do using snprintf(), strlen() etc. Note that if you marshal your reply in memory like this, your reply will be limited to the length of the array which will be constrained by the amount of SRAM available to you, which is not very much on an Arduino.