I am trying to setup TCP communication between a client and a server in different networks. Since I do not own a public server and don't want to setup port forwarding, an option was to use TCP tunneling services like pinggy.
I use pinggy through an SSH session to their servers. A tunnel is created with the following command:
ssh -p 443 -o StrictHostKeyChecking=no -o ServerAliveInterval=30 -R0:localhost:5000 tcp@a.pinggy.io
I set up a simple server.py
like this:
import socket
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('127.0.0.1', 5000))
server.listen()
while True:
conn, addr = server.accept()
print(f"Connection attempt: {addr}")
and a client.py
:
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(("...a.free.pinggy.link", 33143))
The IP and port for the client are provided by the tunneling service which is setup to forward anything from their servers to my localhost:5000
I first run the server.py
and then the client.py
on my computer.
The client finishes without error, yet there is never a connection attempt detected at the server.
Every time an attempt is done to connect to the pinggy tunnel, the interface correctly shows this and increments the total connections, so that part seems to be setup correctly. The signal seemingly just isn't forwarded / received by the server.
Changing the address configuration to run fully locally without tunneling through pinggy works, so the code itself doesn't seem to have issues.
I've tried using ngrok (very similar to pinggy, but not through ssh), and it works just fine.
I expect the fact that pinggy is running through ssh not to be a problem, since using it to forward TCP connections to a minecraft server hosted locally also worked.
Initially, I expected it to be a firewall problem, so I temporarily turned it off to no avail. If pinggy successfully forwards traffic to a minecraft server, why should it not work with a server running python sockets?
It is not clear whether you are in Windows / Linux / Mac. But as per Pinggy FAQ, windows ssh client sometimes has difficulty in connecting to domains such as "localhost". So it is recommended to use the IP address in the command.
ssh -p 443 -o StrictHostKeyChecking=no -o ServerAliveInterval=30 -R0:127.0.0.1:5000 tcp@a.pinggy.io