arduino web server client.println wireshark view of the ethernet question

Hi,

I have a question concerning the implementation of the webserver code for client.println. Here is what i did, i decided to watch the transmissions using wireshark when the PC goes to the Arduino, and gets the web page. Just to see how the packets were being formed and if they made sense. (You know, speed, net traffic, etc). The HTML could not easily be seen for some reason, but with some work, it became apparent that the arduino is serving up the web page one character at a time, that is, on each back and forth with the computer, the message appears to be being formed as 1 byte long. For each HTTP, the length was one byte!

So, for each byte in the client.println(F'') you end up with over 114 characters being sent, one ethernet frame at a time. 54 going one way, then 60 going into the PC. This means that the single client.println shown below, with almost 100 characters to transmit, will result in 11,400 bytes being transfered. Every single character in the line below consists of a back and forth's between the arduino and the PC.

                   client.println(F("<FORM METHOD='LINK' ACTION='http://192.168.1.177/H\r'><INPUT TYPE='submit' VALUE='Light Brighten'></FORM>  "));

Could someone explain how i get the arduino to send the entire line in one proper frame! I would expect that this would have taken, 54 bytes from the PC, and then about 160 bytes from the arduino, and not 11,400 bytes, for this line.

The stuff seems to work, but appears to be really inefficient use of the network.

Suggestions, comments..

Thanks,
Walt

Does it make a difference if you don't use the F() macro?

Good question. I'll have to try that, but here is the problem if i dont use the F, then then sram gets used up too fast and then the arduino crashes... and you get no reason why. So a few weeks ago, the F macro was suggested to move the data inside the client.print off into the the flash.

Thanks,
Walt,

So a few weeks ago, the F macro was suggested to move the data inside the client.print off into the the flash.

And it's a great idea IF it doesn't cause other problems. I'm just curious whether it does, or does not.

Does it make a difference if you don't use the F() macro?

No, it doesn't. Look at how the Print class is implemented and how the EthernetClient class implements the write method and you know why. If you wanna have a more efficient web server, don't use the print() and println() methods but generate strings (not Strings) that contain the request answer and use the write(buffer, size) method to send them.