Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2016-02

FreePascal TCPIP data tunnel code sample?

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bo Berglund

I wonder if someone has built a program that can be used as a "tunnel" of data from one TCP server to a TCP client on another network? The program should sit in between in a computer connected to both networks (Ethernet and WiFi).
If so I would be grateful to share the solutions.

Reason:
I am trying to develop a client program for controlling a data collection instrument, which has WiFi connectivity only. Its connection is implemented as a WiFi Access Point to which you connect. Then you have access to the data source via TCP port 1001. The source is actually operating via RS232 internally. There is a protocol involved for commanding actions and for transferring data in both directions.

Now, I would like to be able to connect to this unit from my place of coding by having a multi-homed device sitting close to the instrument and connecting to it via the WiFi AP, but at the same time it is also connected to the office network by Ethernet.
The device should run a program to connect it to the data port (TCP:1001) of the WiFi AP and start a TCP server on the Ethernet connection on TCP port 1001.
Then whatever data comes in through the Ethernet port should be sent via the WiFi connection to the instrument.
All data received from the instrument should be sent out to the connected client on the Ethernet connection.
So the program I am looking for should not do anything at all with the data content, except transfer byte-by-byte between the networks.

And this should be running on a Raspberry Pi2B so it can be easily deployed in the place the instrument is located. Meanwhile I can sit in another building and test the actual client code.

Is there something like this available already?

Bo Berglund Developer in Sweden

Reply by email

Bo Berglund

Note: I tried posting this via Gmane in my newsreader, but it did not show up.
So I post it now directly to the mail list.
Must have been lost at Gmane because another post I made later came through. ---------------------------------------------------------------------------- -
I wonder if someone has built a program that can be used as a "tunnel" of data from one TCP server to a TCP client on another network? The program should sit in between in a computer connected to both networks (Ethernet and WiFi).
If so I would be grateful to share the solutions.

Reason:
I am trying to develop a client program for controlling a data collection instrument, which has WiFi connectivity only.
Its connection is implemented as a WiFi Access Point to which you connect. Then you have access to the data source via TCP port 1001. The source is actually operating via RS232 internally.
There is a protocol involved for commanding actions and for transferring data in both directions.

Now, I would like to be able to connect to this unit from my place of coding by having a multi-homed device sitting close to the instrument and connecting to it via the WiFi AP, but at the same time it is also connected to the office network by Ethernet.
The device should run a program to connect it to the data port (TCP:1001) of the WiFi AP and start a TCP server on the Ethernet connection on TCP port 1001.
Then whatever data comes in through the Ethernet port should be sent via the WiFi connection to the instrument.
All data received from the instrument should be sent out to the connected client on the Ethernet connection.
So the program I am looking for should not do anything at all with the data content, except transfer byte-by-byte between the networks.

And this should be running on a Raspberry Pi2B so it can be easily deployed in the place the instrument is located. Meanwhile I can sit in another building and test the actual client code.

Is there something like this available already?

Bo Berglund Developer in Sweden

Reply by email

Koenraad Lelong
to Bo Berglund: I wonder if someone has built a program that can be used as a "tunnel" of data from one…

Op 04-02-16 om 17:17 schreef Bo Berglund:

Show quoted text 36 lines
I wonder if someone has built a program that can be used as a "tunnel" of data from one TCP server to a TCP client on another network? The program should sit in between in a computer connected to both networks (Ethernet and WiFi). If so I would be grateful to share the solutions. Reason: I am trying to develop a client program for controlling a data collection instrument, which has WiFi connectivity only. Its connection is implemented as a WiFi Access Point to which you connect. Then you have access to the data source via TCP port 1001. The source is actually operating via RS232 internally. There is a protocol involved for commanding actions and for transferring data in both directions. Now, I would like to be able to connect to this unit from my place of coding by having a multi-homed device sitting close to the instrument and connecting to it via the WiFi AP, but at the same time it is also connected to the office network by Ethernet. The device should run a program to connect it to the data port (TCP:1001) of the WiFi AP and start a TCP server on the Ethernet connection on TCP port 1001. Then whatever data comes in through the Ethernet port should be sent via the WiFi connection to the instrument. All data received from the instrument should be sent out to the connected client on the Ethernet connection. So the program I am looking for should not do anything at all with the data content, except transfer byte-by-byte between the networks. And this should be running on a Raspberry Pi2B so it can be easily deployed in the place the instrument is located. Meanwhile I can sit in another building and test the actual client code. Is there something like this available already?

Hi,

Isn't this just port-forwarding ? Set up the firewall to forward data to the wired NIC to the device's address and port.

If you want it secure, you could use stunnel.

My 2 cents,

Koenraad.

Reply by email

Kenny D. Lee
to Koenraad Lelong

Are your looking for hybrid tcp/ip proxies & bind to n3tm/c3po?

More some the (snmp) proto-call maybe of help? I know their is an rfc's on the number is ??? I've ported some material look up "overbyte ics sockets" dig around! ________________________________________

Earlier message 55 lines
From: Koenraad Lelong Sent: February 4, 2016 3:10 PM To: Subject: Re: [Lazarus] FreePascal TCPIP data tunnel code sample? Op 04-02-16 om 17:17 schreef Bo Berglund: > I wonder if someone has built a program that can be used as a "tunnel" > of data from one TCP server to a TCP client on another network? > The program should sit in between in a computer connected to both > networks (Ethernet and WiFi). > If so I would be grateful to share the solutions. > > Reason: > I am trying to develop a client program for controlling a data > collection instrument, which has WiFi connectivity only. > Its connection is implemented as a WiFi Access Point to which you > connect. Then you have access to the data source via TCP port 1001. > The source is actually operating via RS232 internally. > There is a protocol involved for commanding actions and for > transferring data in both directions. > > Now, I would like to be able to connect to this unit from my place of > coding by having a multi-homed device sitting close to the instrument > and connecting to it via the WiFi AP, but at the same time it is also > connected to the office network by Ethernet. > The device should run a program to connect it to the data port > (TCP:1001) of the WiFi AP and start a TCP server on the Ethernet > connection on TCP port 1001. > Then whatever data comes in through the Ethernet port should be sent > via the WiFi connection to the instrument. > All data received from the instrument should be sent out to the > connected client on the Ethernet connection. > So the program I am looking for should not do anything at all with the > data content, except transfer byte-by-byte between the networks. > > And this should be running on a Raspberry Pi2B so it can be easily > deployed in the place the instrument is located. Meanwhile I can sit > in another building and test the actual client code. > > Is there something like this available already? > > Hi, Isn't this just port-forwarding ? Set up the firewall to forward data to the wired NIC to the device's address and port. If you want it secure, you could use stunnel. My 2 cents, Koenraad. --

Reply by email

Bo Berglund
to Koenraad Lelong: Op 04-02-16 om 17:17 schreef Bo Berglund: Isn't this just port-forwarding ? Set up the…
Koenraad Lelong wrote 20 lines
Op 04-02-16 om 17:17 schreef Bo Berglund: > Then whatever data comes in through the Ethernet port should be sent > via the WiFi connection to the instrument. > All data received from the instrument should be sent out to the > connected client on the Ethernet connection. > So the program I am looking for should not do anything at all with the > data content, except transfer byte-by-byte between the networks. > > And this should be running on a Raspberry Pi2B so it can be easily > deployed in the place the instrument is located. Meanwhile I can sit > in another building and test the actual client code. > > Is there something like this available already? > > Hi, Isn't this just port-forwarding ? Set up the firewall to forward data to the wired NIC to the device's address and port.

Which firewall?
But you are right in the port forwarding part. I want my new RPi2 unit to forward the communications on port 1001 on the Ethernet side to a specific unit on the WiFi side on its 1001 port.

The scenario is this:
- A device has a WiFi Access Point built in
- Clients connect to this AP via WiFi
- Then they can control the device via TCP port 1001
- The device is located in a remote building
- In the development lab there is no connection possible to the AP
- So I need a proxy of sorts in the remote building
- It should connect by WiFi to the device and its TCP port 1001
- It is also connected by Ethernet to the main network
- So a TCP server should accept incoming connections on port 1001
- Any data coming in on port 1001 from the Ethernet side should be sent to the WiFi side to the device with the Access point
- Likewise data received from the device should be passed along to the connected client on the Ethernet

After some research I have found that this is working just like a proxy server and I found a component in Indy10 that can actually do the entire thing!
It is named TIdMappedPortTCP and it does the following:
- Operates a TCP server on a designated port
- When a client connects to the port it opens a client connection to a remote server (preconfigured server and port).
- Then data are channeled between the two sockets in both direction as I described.

And all of this is available in a single Indy10 component!

I do have Indy10 installed in my Lazarus 1.6RC2 and I can see the component on the palette.
Yet if I create a new console program and enter the used units for the component Lazarus reports that it cannot find the unit! Very strange, since it is installed and visible in Lazarus I assumed that it would also be accessible from code...
Sigh....

Bo Berglund Developer in Sweden

Reply by email

Koenraad Lelong
to Bo Berglund

Op 05-02-16 om 14:20 schreef Bo Berglund:

Show quoted text 28 lines
On Thu, 4 Feb 2016 21:10:54 +0100, Koenraad Lelong wrote: > Op 04-02-16 om 17:17 schreef Bo Berglund: >> Then whatever data comes in through the Ethernet port should be sent >> via the WiFi connection to the instrument. >> All data received from the instrument should be sent out to the >> connected client on the Ethernet connection. >> So the program I am looking for should not do anything at all with the >> data content, except transfer byte-by-byte between the networks. >> >> And this should be running on a Raspberry Pi2B so it can be easily >> deployed in the place the instrument is located. Meanwhile I can sit >> in another building and test the actual client code. >> >> Is there something like this available already? >> >> > Hi, > > Isn't this just port-forwarding ? Set up the firewall to forward data to > the wired NIC to the device's address and port. > Which firewall? But you are right in the port forwarding part. I want my new RPi2 unit to forward the communications on port 1001 on the Ethernet side to a specific unit on the WiFi side on its 1001 port.

Every linux-machine, and the pi is no exception, has a firewall : iptables. You could configure it manually, but myself, I prefer shorewall to configure the firewall.

Koenraad.

Reply by email

Bo Berglund
to Koenraad Lelong
Koenraad Lelong wrote 13 lines
>> Isn't this just port-forwarding ? Set up the firewall to forward data to >> the wired NIC to the device's address and port. >> > Which firewall? > But you are right in the port forwarding part. I want my new RPi2 unit > to forward the communications on port 1001 on the Ethernet side to a > specific unit on the WiFi side on its 1001 port. > Every linux-machine, and the pi is no exception, has a firewall : iptables. You could configure it manually, but myself, I prefer shorewall to configure the firewall.

Well, you got me thinking and look at the RPi possibilities.... Turns out that what I want to do can be realized in the following way without even installing or creating a program or manipulating the Linux firewall:

On the RPi having the WiFi connection:
- Enable net.ipv4.ip_forward in /etc/sysctl.conf and reboot

On other computers in the network:
- Add a route for the WiFi network via the RPi having the WiFi connection for example (the WiFi Pi has IP address 192.168.0.152):

On RPI:
sudo route add -net 1.2.3.0 netmask 255.255.255.0 gw 192.168.0.152

On Windows (admin command prompt):
route -4 -p ADD 1.2.3.0 MASK 255.255.255 192.168.0.152

Once I did this I could reach any IP and port in the WiFi subnet from computers on the Ethernet network.

So I do not have to dig into making a special program for this to work.

Thanks for getting me look for a different way of solving the problem!

Bo Berglund Developer in Sweden

Reply by email