Port unreachable when connecting to EthernetServer

Hi,

I've got an arduino uno + ethernet shield setup and running and am trying to connect to it over a direct ethernet connection from my PC, aiming to get UDP or TCP comms running. The server initialises and runs with an IP inside the local subnet for that ethernet connection, and should accept incoming connections to its port. Oddly, however, it instead returns an ICMP port unreachable message.

The basic shape of the setup sequence is based off some of the provided examples:

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip = {169,254,160,92}; // CONFIGURE THIS AS NEEDED
EthernetServer server(8000);
EthernetClient client;

void setup()
{
  Serial.begin(9600);
  Serial.println("Starting up");
  Ethernet.begin(mac, ip);

  // Check for Ethernet hardware.
  if (Ethernet.hardwareStatus() == EthernetNoHardware)
  {
    Serial.println("Ethernet shield was not found!");
  }

  // Check for Ethernet cable connection.
  if (Ethernet.linkStatus() == LinkOFF)
  {
    Serial.println("Ethernet cable is not connected!");
  }
  server.begin();
  Serial.println(Ethernet.localIP());
  if (server)
    Serial.println("Server Running");
}

void loop()
{
  client = server.available();
  if (client)
  {
    Serial.println("Client found");
    while (client.connected())
    {
      if (client.available())
      {
        // Do stuff, exchange more messages, etc
      }
    }
  }
}

All the appropriate serial messages print to signal success. The wireshark logs show that when trying to communicate to it, the device is identified and responds to the ARP request with the correct MAC address. Thus,


Greatly appreciate if anyone has any ideas why this might be happening and how to fix it.

169.254.0.0/16 is the link local block. You shouldn't use it for fixed addressing. If you have a good reason to use it, you must specify the network mask to the Ethernet library because by default the library assumes a class-C network (/24 or 255.255.255.0).

1 Like

Thanks, I didn't think of that causing an issue but it definitely was.

I'll try to assemble that now!

Edit: It works enough to get me onto a different error message (WinError 10054), so definitely progress. Apologies for the delay in responding, I was forced away from this project for a few months.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.