arduino/reference-en

Error in Ethernet client.connect() example

Elizabeth-0 opened this issue · 1 comments

A user found the next issue:

"This page has a mistake in the example. if (client.connect(server, 80)) should be if (client.connect(server, 80) == 1).

The reason is because all non-zero values convert to ‘true’. This means that, for example, a timeout condition would also be detected as a successful connection. I suspect this mistake was made because it was assumed that values <= 0 evaluate to ‘false’.

Ref: https://www.arduino.cc/reference/en/libraries/ethernet/client.connect/ "

Hi @Elizabeth-0. Thanks for your report. The example is correct. The part that was incorrect is the documentation of the return values. EthernetClient::connect only returns 0 or 1. The incorrect documentation has now been fixed: arduino-libraries/Ethernet#240

Please note that this issue tracker should only be used when reporting problems with the content hosted here, which is for the Arduino Language Reference pages you see listed here:

https://www.arduino.cc/reference/en/

In the future, if you want to report a problem with a library reference page, make the report in the repository of that library, where the library reference content is hosted.