Fighting with Ethernet library, finally got something running stable, but why??

hi,

so i have been developing a sketch that works as an ethernet client and posts some data to a WSGI apache server that stors it in a MySQL database...

for the last few weeks (feels like months) i have been fighting with the stability of the sketch (as it seems many others have as well).

normally i could post to my server for an unpredictable amount of time then the sketch would just freeze!! uggh..

however last night i made a seemingly minor change and eureka! its been stable all night. even at 3 http requests per second!!

so heres what i did:

Problematic code:

      client.println(outBuffer);
      client.println("Host: www.arduino.cc");
      client.println("User-Agent: arduino-ethernet");
      client.println("Connection: close");
      client.println();

Seemingly ok code:

      #define httpHeader "\nHost: www.arduino.cc\nUser-Agent: arduino-ethernet\nConnection: close\n"
      strcat(outBuffer,httpHeader);
      client.println(outBuffer);

so why the dramatic difference?? anyone got any ideas? im not 100% confident that i fixed anything but so far my tests are promising. also as a note, i am using the Seedstudio Ethernet Shield V1.0 with the Wiznet 5100 on an Arduino mega 2560.

thanks.

Each client.println() statement causes a new packet to be sent. Given that you were sending multiple packets, and are now sending one, I rather expect that more of the current packets are getting through in the correct order (since it's rather hard to get one packet out of order).

If you want it to work fast, use client.write rather than client println. It will need an extra "\n" tho.

      #define httpHeader "\nHost: www.arduino.cc\nUser-Agent: arduino-ethernet\nConnection: close\n\n"
      strcat(outBuffer,httpHeader);
      client.write(outBuffer);

Thanks for the explanation and suggestion.

I have updated "print" to "write" and all seems to be running great!!

now its time to go re-flash all the machines :smiley:

Thanks again!!!!!!