Ethernet Shield Connection Problem

This might be more of a router question than a programming question, but I am not sure what is going wrong; I am hoping someone else has seen this before and can at least point me into the right direction. I have an Arduino Mega with an official Ethernet shield hooked into it, and the Arduino is configured as a server which is broadcasting messages. I created a C# application which acts as a client which listens in on the broadcast. I have a static IP set up for the Arduino which is 192.168.1.200:9012. Here is the problem i am experiencing:

When I try to connect the client application to the Arduino, if i set the ip address to connect to 192.168.1.200:9012 (ie, everything stays within my local network), everything works fine. Now, if I go to google and type "whats my ip" and find what my routers outside IP address is (for giggles lets say its 123.123.123.123), and set the client to point to 123.123.123.123:9012, I keep getting a connection error saying:

No connection could be made because the target machine actively refused it 123.123.123.123:9012

I assume this is the router throwing away the connection, but it could maybe be the Ethernet shield refusing it as well? I did set up port forwarding on the router, and allowed the port through the firewall (even tried disabling it and still nothing). The code i am using to connect is below:

Arduino:

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 200);
IPAddress gateway(192,168,1, 1);
IPAddress subnet(255, 255, 255, 0);

EthernetServer server(9012);

void setup()
{
        //Ethernet.begin(mac, ip);
        Ethernet.begin(mac, ip, gateway, subnet);
        server.begin();
}

void loop()
{
        EthernetClient client = server.available();
	
	// If a client was found
	if ( client )
	{
		// Read the bytes sent by the client and form a message
		char message[UI_MSG_SIZE];
		client.readBytes(message, UI_MSG_SIZE);

		// Send the message to be processed 
		processMessage(message);
	}
}

c#:

_client = new TcpClient("123.123.123.123", 9012);

It seems to me that this shouldn't be this difficult, but I have been fighting this for a while. Anyone have any ideas?

Your Ethernet.begin() call is not correct. It should be this:

Ethernet.begin(mac, ip, gateway, gateway, subnet);

SurferTim:
Your Ethernet.begin() call is not correct. It should be this:

Ethernet.begin(mac, ip, gateway, gateway, subnet);

I just gave that a try. It still wont connect.

–edit

I also checked to make sure that the dns was truly the same as the gateway. It is. If I run ipconfig /all on my pc, I see the following:

IP Address (v4): 192.168.1.58
Subnet mask: 255.255.255.0
Default Gateway: 192.168.1.1
DNS Server: 192.168.1.1

I have the Arduino configured the same way (with the different IP of course).

Did you port forward that port to the private ip of the Arduino in your router? Or put it in the DMZ? Allowing the port through the firewall is just part of it.

SurferTim:
Did you port forward that port to the private ip of the Arduino in your router? Or put it in the DMZ? Allowing the port through the firewall is just part of it.

I did not have a DMZ set up. I do now. Still nothing.

Port forwarding is still enabled. The start and end port are set to 9012, and the server ip is the internal local ip of the arduino (192.168.1.200) as it should be.

This must be a router firewall response.

No connection could be made because the target machine actively refused it 123.123.123.123:9012

The Arduino does not actively refuse any connection. It either accepts it, or ignores it.

edit: The three things a firewall can do is

  1. accept
  2. reject (active)
  3. drop (passive)

The Arduino library doesn't support the reject. Only accept and drop.

SurferTim:
This must be a firewall response.

That is what I originally thought too. But I currently have the firewall off. I cant think of any other firewall or anything which would be blocking it.

Does your router have a html setup function on port 80?
http://123.123.123.123
Can you reach that from the internet? Just as a test?

SurferTim:
Does your router have a html setup function on port 80?

It does

SurferTim:
http://123.123.123.123
Can you reach that from the internet? Just as a test?

And I can!

That indicates a couple things.

The first thing is your ISP is not blocking the request.

The second thing is your DMZ is not working. If it was, the router html setup page should not have responded. The DMZ normally forwards all ports to the target ip. The Arduino will not respond on port 80 with the setup you are using in it. ??

The active refusal is a reject from a router or firewall. The Arduino does not send a reject message. It either accepts or drops (ignores) the connection.

Interesting turn of events. I got it working. Turns out it helps if the firmware on the router is up to date. Works perfectly now. Just had my buddy from the next town over dump water on my floor to verify (the Arduino is controlling valves/pumps which move liquids around). Man I love software/electronics haha.

Thanks guys.