I don't understand your answer, could you precise?
What I want in fact is the ability to change the port of my application because if the port is already taken by another device on the network, I would like to have the ability to change it in case of conflict.
john_lenfr:
I don't understand your answer, could you precise?
What I want in fact is the ability to change the port of my application because if the port is already taken by another device on the network, I would like to have the ability to change it in case of conflict.
What difference would it make if another IP has the same port in use? That would not be a conflict unless both devices had the same IP.
But from outside the local network, if 2 devices have the same port I'm bloked.
No. Only if you mess up the port forwarding in your router. You can port forward different ports on your public IP to different IPs with the same port on the localnet. At least I can with my router.
SurferTim:
What difference would it make if another IP has the same port in use? That would not be a conflict unless both devices had the same IP.
No. Only if you mess up the port forwarding in your router. You can port forward different ports on your public IP to different IPs with the same port on the localnet. At least I can with my router.
No, you can't do that because from the outside you can only make the difference when calling by the port.
Let's say your public IP adress is 345.345.345.345 (for the example ok, I know 345.345.345.345 does'nt exist)
If you redirect port 80 onto 2 different IP adresses:
what is going to happenend when you type http://345.345.345.345 ?
Is your web server on 192.168.0.2 or 192.168.0.3 executed?
The only way to do for me is to take 2 different PORT to make the difference from the outside:
If you have:
Public IP: 345.345.345.345
Internal IP1 : 192.168.0.1:80
Internal IP2: 192.168.0.2:90
So from the outside you could call:
345.345.345.345:80 will be redirected to 192.168.0.1 device
345.345.345.345:91 will be redirected to 192.168.0.2 device
So you could have your web server on 192.168.0.1:80 and an Arduino on 192.168.0.2:90
john_lenfr:
The only way to do for me is to take 2 different PORT to make the difference from the outside:
If you have:
Public IP: 345.345.345.345
Internal IP1 : 192.168.0.1:80
Internal IP2: 192.168.0.2:90
So from the outside you could call:
345.345.345.345:80 will be redirected to 192.168.0.1 device
345.345.345.345:91 will be redirected to 192.168.0.2 device
So you could have your web server on 192.168.0.1:80 and an Arduino on 192.168.0.2:90
Is that correct?
Partly. You can also use port 80 on both the 192.168.0.1 and 192.168.0.2 devices.
345.345.345.345:80 will be redirected to 192.168.0.1:80
345.345.345.345:91 will be redirected to 192.168.0.2:80
Take look here for an example. This is a Netgear router. Look at the second pic that has "Port Forwarding / Port Triggering"on that page and the instructions below it. The start port is 91, and the end port is 80 91.
edit: This is the rest.. You must deselect "use same port for internal". Then enter 80 for start and 80 for end.
Thanks, zoomkat. He's stuck using port 91 on the ethernet shield. That shows me two things.
Netgear routers can't do that.
My Routerboard/MikroTik routers can.
edit: But this does not explain why the OP wants to change the port "on the fly". With a primitive router like the Netgear, it certainly wouldn't have any fallthrough capability.
Can you give a little more detail on the "that" in the above statement? The discussion is some what rambling between router configuration and changing an arduino server port on the fly.
That wasn't very clear. The netgear does not do a full DNAT. It won't change the port according to your pic. It can port forward from the public IP port 91 to the localnet port 91, but can't change the port.
My routers can also DNAT the port. I can change the public IP port 91 to a localnet IP port 80. It may be that some Netgear routers can do that also, just not the one you have.
My question to the OP is why the need to change the port on the fly? What is gained by that? Can the OP change the router's DNAT on the fly?
edit: I played with the server code a bit and got it to change ports on the fly if that will help you. I used ports 80 and 8080 as a test. You can change that to anything you like.
// add this to includes
#include <utility/socket.h>
// in global variable area
EthernetServer server1(80);
EthernetServer server2(8080);
// set server to server1
EthernetServer server = server1;
// in setup
server.begin();
// to change ports
// change server to server2
server = server2;
// close all sockets
for(byte i = 0 ;i < MAX_SOCK_NUM;i++) {
close(i);
}
// start server2
server.begin();