1

I'm building an web app (Server A) that communicates with a remote server (Server B) that is connected to the internet.

Server B resides behind a NAT and is listening to communication on 3 non-standard ports.

In a typical scenario, in order for me to deploy multiple remote servers across different networks and to have it communicate with the parent web app (Server A), each of these servers have to have the routers manually configured to forward the respective ports to a static ip in which Server B is configured.

I'm looking for a way to solve this problem of having to configure each router individually and manually for each deployment. Port forwarding has to be done because Server A has to communicate with Server B and has to initiate the conversation.

I'm asking if there's a way for Server B to initiate the communication rather than the other way round so that port forwarding doesn't need to occur.

Server B would just need to call home, open up what ever sockets/ports necessarily (this is where I need your help for information) and all communication would be done via these opened ports without Server A ever needing to know the ip of Server B, and having to talk to the router to handle the forwarding.

Is this scenario possible?

Edit: Added some more details:

Basically I have created a webapp (Server A) that talks to multiple 3D print servers that has an REST API exposed. The print server API servers are all listening on a non-standard port of 8721.

Right now, manually on my webapp I am configuring manually to point to each print server via their external ip address and port-forwarded port. As you can probably tell this is going to create a shitload of problems as most of these external ip addresses are going to change due to most home/consumer networks not having a static ip.

This means that I have to find out everytime the ip address is changed and manually modify my records on my webapp.

I imagine (and hypothesize) that one of the best way to solve this is to not let the webapp worry about where each of these print servers are located but rather let the print servers themselves tell the webserver where they are.

I'm trying to solve 2 problems:

  1. The external ip addresses being dynamic and not static (as mentioned above)
  2. Port-forwarding/firewall imposed by the home networks. In the event that there are multiple print servers in a home network, this means that in order to reach each server individually, the home router needs to know how to route each unique port which needs to be configured on both the webapp and the home router side to the right print server (as all of them are listening on 8721).

Sorry for the lengthy post. I', still relatively new to the whole socket programming part of things and I'm hoping that someone would be able to point me to where I should be looking to find out more information on how to do the above.

2
  • Without some specifics about what software you're using I don't think anybody here can answer this, except to say: "Yes-- computers can be programmed to do that." Tell us more about the software and we can give you specific answers. Apr 16, 2014 at 2:24
  • Thanks guys. I've edited my post to add more details about what I'm trying to achive.
    – David C
    Apr 16, 2014 at 4:14

2 Answers 2

1

Yes, this is possible. This can be automated easily with UPnP port forwarding, if enabled on the NAT host/device, if security is not a consideration. If you do not want to use UPnP, for example, because security is a consideration, you can achieve this using another API to access your NAT devices. UPnP is very common in home routers.

You may wish to use another server to communicate the IP addresses and port numbers of Server A and Server B at a static IP address or FQDN that is directly accessible on a static port. This can be done by storing the data in a text file, for example.

As @Evan said, without specifics about what you are really trying to achieve, this is all I can say.

1

Assuming you control the print server code then, sure, you can have the print server connect out to your servers obviating the need to worry about NAT in the remote networks. This is, for example, how "GoToMyPC" and "LogMeIn" work-- making persistent connections outbound through the firewall to servers.

There are protocols that can allow you to "punch through" NAT but, frankly, unless both endpoints are behind NAT that you can't control I'd argue that those protocols (STUN, etc) are too much work for too little return.

You'll want to think about how your print servers locate the central server. It's tempting to just use DNS names, but you should think about changes you might make later on in your server infrastructure (in scaling, for example). I'd point you toward SRV records as a mechanism for the print servers to locate their central server. The SRV record already has built-in abstraction for high-availability and priority weighting.

2
  • Thanks! I think's exactly what I'm looking for. How do apps like GoToMyPC and LogMeIn do that?
    – David C
    Apr 16, 2014 at 7:08
  • They make persistent connections outbound through the firewall to servers on the Internet. Apr 16, 2014 at 8:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .