Hello,
I was trying to visualize the traffic generated by the web client in Examples > Ethernet
by David A. Mellis created 18 Dec 2009, modified 9 Apr 2012 by Tom Igoe, based on work by Adrian McEwen
The analyzer is a windows machine running a bridge and wireshark capturing traffic to/from arduino, please refer to attached figure
What i do not understand is all the packets (also to port 80) which always precede the http request (highlighted in yellow) coming from arduino.
These packets appear when the request is to google or to a wamp server on my LAN
when i replace arduino by a window machine making the same request with wget, the first packet is the always http request
I'd greatly appreciate if anyone could shade some light on this mystery
The W5100 library perhaps does not buffer outgoing data, which result in so many TCP packets, and no one cares.
I care. I manage the packet size by the character array size I use to send packets with client.write. All my examples in the playground use character arrays to send bigger packets.
Some examples are not very internet friendly tho. They send a bunch of packets just to send one request.
edit: Here are two examples. The first sends 4 packets.
client.println("GET /mypage.php HTTP/1.1");
client.println("Host: mydomain.com");
client.println("Connection: close");
//...and the worst offender! A cr/lf sent in its own packet. :(
client.println();
I understand: The request is segmented by arduino (here) because of the way the code is written. Wireshark (and of course the server) who's looking for \r\n\r\n knows when it's the last segment and shows the whole request on frame 19 though this frame has just the last \n byte. Indeed, when coded per SurferTim, the request is sent with just one 129 bytes frame.
The total buffer inside the W5100 is 16kbyte, and it has 4 sockets, that is 2048 byte per buffer (a single TX or RX buffer for a socket) which is the number that is also used in the Ethernet library.
The data to the Ethernet is not written in a buffer, but directly passed on via SPI to the W5100 chip.
Therefor, the total length for a long text for a single Client.write can be up to 2048 (if the TX buffer is empty).
The free size could be checked with "W5100.getTXFreeSize(socket)", but with an Arduino Uno or Mega the 2048 bytes is probably never completely filled.
I still prefer seperate code lines in my sketch. I write it like this:
// optimize for single packet
client.print(F( "GET /mypage.php HTTP/1.1\r\n"
"Host: mydomain.com\r\n"
"Connection: close\r\n"
"\r\n\r\n"));
Will the client.print() instead of client.write() still write the complete string ? I need the string to be in flash memory.
@Peter_n: That way is fine. zoomkat does the same thing with his client.print stuff.
AFAIK, the largest packet the w5100 can send is 1492 bytes. I don't think it can send anything larger than that. I could be wrong.
I use client.write because the call is faster, and I normally have the request formatted into a character array. If I need to build an array, I use strcpy_P and strcat_P and the PSTR macro. That keeps the static strings in program memory until I need them. Here is an example from my server code I have on the playground. The tBuf variable is a character array.