I'm working into a project that needs to implement a Reverse Socks5 connection. In practical terms, the browser (Chrome/FireFox/Opera/IE) will connect on a local socks server (127.0.0.1:8080), and on this same server I will have a remote client connection on another port (192.168.0.9:8081).
Once I open a website on the browser, multiple requests can be done (html, images, scripts...), I should pass them from the port 8080 to the connection on port 8081. The remote client should execute the requests and send the answer back over port 8081, once it comes I should redirect this answer over the tunnel to port 8080 and deliver to browser.
I tried to create a diagram to show my data flow:
(https://i.imgur.com/kX1Hj2P.png)
I'm working into a project that needs to implement a Reverse Socks5 connection. In practical terms, the browser (Chrome/FireFox/Opera/IE) will connect on a local socks server (127.0.0.1:8080), and on this same server I will have a remote client connection on another port (192.168.0.9:8081).
Once I open a website on the browser, multiple requests can be done (html, images, scripts...), I should pass them from the port 8080 to the connection on port 8081. The remote client should execute the requests and send the answer back over port 8081, once it comes I should redirect this answer over the tunnel to port 8080 and deliver to browser.
I tried to create a diagram to show my data flow: enter image description here
I pretend to use Indy(IdTCPServer / IdTCPClient) classes, but doesn't matter what class will be used.
The problem comes when I need to send the requests over the connection on port 8081:
- I don't know how many requests the browser will make, so I open only 1 connection on port 8081. Should I pass all the requests over this connection?
If the answer for the first question was Yes, once I have the Socks5 Answers to deliver back, how the Server will know the connection on port 8080 that the answer should be delivered?
If the answer for the first question was No, so I should create new connections on port 8081 to process the requests. Once I receive one new connection, I send the request to this connection, execute on client, deliver back over this connection. But I should keep track of the browser connection that did the request, to deliver it. And more, I should send a text or something, over the first connection on port 8081, to request a new connection. Isn't that over complicated?
Am I missing some point on how to construct a TCP tunnel properly? Is not possible to make a tunnel that will just pass requests/answers to the right connections, without interference of the Server?