Recent

Author Topic: How to create a "TCP/IP relay" server?  (Read 703 times)

BosseB

  • Sr. Member
  • ****
  • Posts: 358
How to create a "TCP/IP relay" server?
« on: April 24, 2021, 03:45:27 pm »
I am using Indy in a server for handling external equipment which is monitoring dams and waste dumps for leakage.
This system might be powered by solar cells on very remote locations.

The server has been ported from Delphi on Windows to FreePascal on Linux and runs on a RaspberryPi4 device.

The old client on Windows works also with this new server but to accommodate the differences between Windows and Linux I have had to also port the client application to FreePascal/Lazarus and add Unix/Windows difference handling.
When doing this I have replaced the "native" Delphi TCP/IP components with Indy server and client objects in both applications.

So now (almost) everything is running as intended but I have run up against a connectivity problem...

When the system is deployed it will use a mobile broadband connection to the Internet and I have found that the way these are done today often (always?) do not include for the router to get a public IP address so that one can use DDNS to find the address and connect to the server on RPi4 for configuration, monitoring and data download.

So now I wonder if there is a way to use Indy to make some kind of "relaying server" that could run on a Linux box with public IP to which the RPi4 remote server can connect and to which our client could also connect and specify which system it wants to talk to, whereupon the relaying server channels all traffic from the client over to the connected remote server and vice versa (if it is actually connected) so that both can start talking to each other using our already established specific protocol?

I don't know what this kind of operation could be called so it is hard to google, I hope you get the idea anyway...

(Also posted on the Atozed forum)
« Last Edit: April 24, 2021, 03:47:05 pm by BosseB »
--
Bo Berglund
Sweden

dseligo

  • Sr. Member
  • ****
  • Posts: 315
Re: How to create a "TCP/IP relay" server?
« Reply #1 on: April 24, 2021, 11:54:43 pm »
I don't know about Indy, but I used ssh tunnel on several occasions for such reasons. When I needed to, I connected from remote machine (which I couldn't access to) to machine where I could get access with -R option. Then I could connect back to remote machine through port that was opened.

BosseB

  • Sr. Member
  • ****
  • Posts: 358
Re: How to create a "TCP/IP relay" server?
« Reply #2 on: April 25, 2021, 12:58:36 am »
Thanks for the suggestion.
This means that:
1) I need to have a way to command the remote RPi to connect via the SSH tunnel to the predefined server (I need to figure out how that is going to be done).

2) Then on this server I need to have a socket service running which my client application can connect to through the router via port forward.

3) The socket server needs to be able to connect a socket connection to the remote RPi at its comm port following the client connection.

4) Next it needs to forward whatever data comes in from the remote RPi over to the connected external client and send everything the client may supply to the RPi via the socket connection.

Seems like it would be doable, but since the final connection is via the TCP/IP sockets maybe the SSH tunnel is superfluous?
The remote RPi could as well connect a TCP socket connection to the intermediate server instead and use that connection as described above?
--
Bo Berglund
Sweden

dseligo

  • Sr. Member
  • ****
  • Posts: 315
Re: How to create a "TCP/IP relay" server?
« Reply #3 on: April 25, 2021, 11:26:35 am »
1) I need to have a way to command the remote RPi to connect via the SSH tunnel to the predefined server (I need to figure out how that is going to be done).
I had cron job that polled status on server every 5-15 minutes. When I needed to connect, I had set status on server and then wait (from maximum 5 to 15 minutes) while my tunnel became available.

Quote
2) Then on this server I need to have a socket service running which my client application can connect to through the router via port forward.

SSH server.

Quote
3) The socket server needs to be able to connect a socket connection to the remote RPi at its comm port following the client connection.

When you connect through ssh tunnel, you work directly on remote machine.

Quote
4) Next it needs to forward whatever data comes in from the remote RPi over to the connected external client and send everything the client may supply to the RPi via the socket connection.

Seems like it would be doable, but since the final connection is via the TCP/IP sockets maybe the SSH tunnel is superfluous?
The remote RPi could as well connect a TCP socket connection to the intermediate server instead and use that connection as described above?

Yes, maybe it is superfluous, but as I said in my first post, I don't know solution with Indy.
I used it this way because it was fast and simple way for me to achieve access to remote clients - I didn't have to setup port forwarding on routers on the client machine side.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 957
    • Lebeau Software
Re: How to create a "TCP/IP relay" server?
« Reply #4 on: April 26, 2021, 07:22:34 pm »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

 

TinyPortal © 2005-2018