3

I have a client to connect multiple devices. For not paying monthly static IP fee per device. We plan to change the architecture. In this new architecture devices connect to a server. Instead of writing a server. I am looking for an intermediate solution.

Current Architecture:

--------------                           ------------
| POLLER APP | ------------------------> | DEVICE 1 |
--------------                           ------------
         |  |
         |  |                            ------------
         |  ---------------------------> | DEVICE 2 |
         |                               ------------
         |
         |                                   ...
         |
         |                               ------------
         ------------------------------> | DEVICE N |
                                         ------------

Poller app sequentially connects to every device with static IP.

Solution 1:

--------------                           ------------
|   SERVER   | <------------------------ | DEVICE 1 |
--------------                           ------------
         A  A
         |  |
         |  |                            ------------
         |  ---------------------------  | DEVICE 2 |
         |                               ------------
         |
         |                                   ...
         |
         |                               ------------
         ------------------------------  | DEVICE N |
                                         ------------

In this solution (Which i don't prefer) I must write a server app for the devices that have dynamic IPs.

Solution 2 (Which I looked for):

                                         ------------
--------------                           |          |               ------------
| POLLER APP | ------------------------> |     X    | <------------ | DEVICE 1 |
--------------                           |          |               ------------
         |  |                            |          |
         |  |                            |          |               ------------
         |  ---------------------------> |          | <------------ | DEVICE 2 |
         |                               |          |               ------------
         |                               |          |
         |                               ------------
         |                               
         |                               ------------
         ------------------------------> | DEVICE S |
                                         ------------

X Box works as a server. Remote devices can connect to this box and Poller app can connect to this server locally or over Unix domain sockets. X Box repeats the messages that comes from local connection to remote devices.

My question is: Is there any complete or partial solution that can help me to achieve this. May I directly bind two incoming connection easily?

2 Answers 2

0

Depending on how often the poller contacts the devices, it may be enough to use Dynamic DNS. With dynamic DNS, you don't need a static IP address at all, you only need a domain name that you control with a provider that supports dynamic DNS. Every time a device (re)connects, it connects to the DNS provider to declare its new IP address. The downside of this approach is that it takes a few minutes for the DNS information to propagate, so each time the IP addresses change, there'll be a few minutes during which your devices are unreachable.

If you want to have a single box with a static IP address, then what you're looking for is called NAT (network address translation). The idea is that when box X receives an incoming TCP connection on a certain port, it consults a table to decide which device to forward the connection to (or to take the connection for itself). This happens at the level of IP packets and TCP connections, so you don't need any special software on the poller or on the device, you only need to configure the poller to use the same IP address but different port numbers for each device.

NAT is supported by pretty much any device appliance. For example, it's what home routers do so that you can connect multiple devices (computers, phones, etc.) to the Internet even though your Internet service provider only provides you a single IP address. In this case, the device performs source NAT (SNAT): the router modifies the source of the TCP connection to be itself instead of the computer (and conversely the destination of packets in the other direction is modified). In your case, you want destination NAT (DNAT), which modifies the destination of the packets in the client→server direction and the source of the packets in the server→client direction. If the devices need to open connections to other machines on the Internet, you can make box X do both DNAT and SNAT.

On Linux, you can use iptables to configure NAT. See the netfilter howto or any of the many Linux NAT tutorials on the web.

3
  • Thanks for your answer. Those devices are proprietary. It would be great if devices can inform the server their recently assigned IP addresses. Devices have two options: client mode and server mode. So Dynamic DNS registration or self informing is not possible. And we need a solution that binds two incoming connection. So its not a traditional port forwarding or address translation (XNAT) issue. First we must achieve the connections via a dummy server. Than must establish a pipe between external and internal connections. May 23, 2015 at 6:09
  • @FıratKÜÇÜK Discriminating multiple incoming connections is exactly what DNAT means. May 23, 2015 at 9:53
  • Yes but mind the arrow directions. We want to glue the matched incoming connections not route them. You may want to look at the code that i wrote. It may explain the problem better than me. May 23, 2015 at 17:02
0

I wrote a little Python script for this. Maybe there is a shorter way to achieve this but i couldn't find. My script creates 1 external server that listens 1560 for device connections. For every device connection it creates a new internal server. After this. It transfers messages between matched internal and external connections.

                  B I N D E R
                 -------------
                 | INT |  E  |                 ------------
-------> (60000) | SRV |  X  | (1560) <------- | DEVICE 1 |
                 |     |  T  |                 ------------
                 |-----|  E  |
                 | INT |  R  |                 ------------
-------> (60001) | SRV |  N  | (1560) <------- | DEVICE 2 |
                 |     |  A  |                 ------------
                 |-----|  L  |
                 | INT |     |                 ------------
-------> (60002) | SRV |  S  | (1560) <------- | DEVICE 3 |
                 |     |  E  |                 ------------
                 |-----|  R  |
                 | INT |  V  |                 ------------
-------> (60003) | SRV |  E  | (1560) <------- | DEVICE 4 |
                 |     |  R  |                 ------------
                 -------------

The script needs python-twisted dependency. I created a github repository for that: github.com/codvio/binder

You must log in to answer this question.

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