I have a web application uses a tcp socket to connect to an outside server (of mine). How can I tell the outside server, what Port number of the tcp socket has been assigned, by the router, on the tcp socket end?
I am trying to create a tcp hole punch.
Thank you,
Tim
I understand that ComputerA tcp socket has to connect to the outside world on ComputerB. Then ComputerC connects to computer B who then hands off ComputerC to Computer A but on the same port that ComputerA made its outgoing connection to Computer B on.
ComputerA is normally listening on port 80 or 8080. But the router has to route ComputerC request to A and only knows to do that if C comes back on the same port as the outgoing A…
I think I see what you’re trying to do, I just can’t see how you can achieve the result you’re looking for. You may need to pass the Session ID from A to B who passes it to C to reconnect back to A using that Session ID.
@Tim Seyfarth
Ive just read this thread 3 times and am thoroughly confused. You seem to be using Computer B and Router in your statements interchangeably, but what that middle device is determines how you might solve this.
FWIW, the port numbers of an outgoing connection rarely has anything that do with the ports for incoming connections (unless youre doing something like ftp), so I dont think what Youre describing gets you what you want.
If youre already creating a tcpsocket from Computer A to Computer C, why not just use that as a 2-way communication channel?
Computer B is not the router, it is a Computer on the internet, on a separate network (hosted at my office). Computer A is a web app that can be anywhere in the world and is behind a NAT. Computer C is another computer that a user is trying to connect to Computer A and is behind yet another NAT.
Without setting up port forwarding on ComputerA’s network, Computer C cannot access it, even with port 80, or 8080 since the router (on the ComputerC’s newtwork) has no way to know where to point it to. Hence the reason to create a TCP Hole punch.
Here’s another link that explains what I am trying to do I wish it was simpler. UPnP does not work reliably - at least for me and one other user of Xojo, maybe someone else has gotten it to work?
One more question… are all of these computers controlled by you or your company? If so, you might consider something like ZeroTier which bypasses all of this stuff.