Bridge: External ip Connection Questions

Using the Arduino Yún Bridge example sketch, I am able to change the Pin13 LED state both from an internal and external ip, but I have two issues.

The first issue I have is not understanding why all 3 of the following substitutions allow me to connect both internally and externally and change the LED state:

server.listenOnLocalhost(); // I thought this excluded external connections?

server.noListenOnLocalhost(); // I thought this was necessary to connect externally?

// server.listenOnLocalhost(); //Commented out. Still works.

The second issue I have is not understanding why the following substitution causes the following error on the external connection: "Could not connect to Yunserver 146 connection refused":

YunServer server(8081); //I thought this would allow me to forward the external connection
//through my router to the Yun port 8081?

I am able to change the Yun port by leaving the line as is:

YunServer server;

and editing the upphtd file. Then I am able to forward the external connection to the Yun port 8081.

So even though I can get the behavior I want, I still would like to understand what's going on.

bro65:
The first issue I have is not understanding why all 3 of the following substitutions allow me to connect both internally and externally and change the LED state:

I haven't used the yunServer class but I will take a stab at your question, based on more general Linux networking knowledge. localhost probably refers to the loopback interface, which is typically known to the host and only the host as, 127.0.0.1. So, a host which is listenOnLocalHost, can connect to itself using the 127.0.0.1 address, whatever the IP address assigned by the network. A host which is not listenOnLocalHost, will still accept connections to the network assigned IP and pass data to/from your application, but presumably, for the host to connect to itself, it must use the network assigned IP address. The difference is subtle and the implications would mostly be felt by the host's own firewall.

The second issue I have is not understanding why the following substitution causes the following error on the external connection: "Could not connect to Yunserver 146 connection refused":

That message means the connection request was actively refused, which typically is what a host does when it is not listening on the specified port. The yunServer documentation indicates the server always listens on 5555 and does not suggest how that might be changed. It appears you can not change the listen port from Arduino code.

I am able to change the Yun port by...editing the upphtd file. Then I am able to forward the external connection to the Yun port 8081.

Personally, I would redirect the port at the router and keep the Yun as documented. This is mainly a network management consideration and I like to keep all my address and port translations in one place, on the network border.

There should be a field on the router's port redirection page to specify the destination port inside the network. The router should also handle redirecting connection requests from inside, so all clients can use the same, outside, IP and port number to reach the server. However, I am aware that cheap domestic routers don't always handle translation from inside, very well.

So even though I can get the behavior I want, I still would like to understand what's going on.

Hope it helps.

You can change what port the Yun listens on by using the following command.

YunServer server(port_number);

Where port_number is the port that you want to listen on.

Example:

YunServer server(8008); //Sever will listen on port 8008