Hi all!
I realized a bug in the example code posted on some reference pages of EthernetServer:
In all those pages, the Ethernet object is called by the wrong sequence of parameters:
// initialize the ethernet device
Ethernet.begin(mac, ip, gateway, subnet);
The correct sequence of parameters is posted in the Ethernet.begin() reference page:
Ethernet.begin(mac, ip, dns, gateway);
This results in a confusing problem:
- The example code works fine on IP link-local level, where no gateway is needed, eg. when you connect the Arduino Ethernet-shield directly to your PC. - Probably the reason nobody realised this yet.
- The example code does not work when the Arduino is behind a router in another subnet, because the gateway is probably set to 255.255.255.0, which is most certainly wrong.
The fact that the DNS is also wrong is not relevant, because the EthernetServer does not need to know a DNS server in the first place.