I spent a good half a day today trying to figure out why my ethernet client code suddenly does not work anymore.
It turns out if you are using "hostname" to connect, ethernet client will do a dns lookup, and if dns lookup fails, connect returns a negative value, which tests to TRUE if you do this code
if (client.connect("www.google.com",80)) {
//apparently connected, NOT if there was a dns error.
}
The correct code is to explicity test for 1
if (client.connect("www.google.com",80)==1) {
}
I think someone should change the WebClient example that comes with Arduino Ethernet library and update the documentation as well.
edit: I changed my playground web client examples to evaluate to success if return value is 1 rather than not 0.
After a test and then evaluating the dns library code, the "INVALID RESPONSE" is a return value value from -4 to -10. I tried connecting to a non-existent domain and the client.connect() function returned -5.
@doughboy: Did you want to report the error? Here is a link to the github for Arduino. That is where we are supposed to report website, example, and reference errors.
Update: The reference return value was changed to reflect the correct return values, but the example on that page is still incorrect. I reported that error to Scott Fitzgerald, the person who did the change.