Port Forwarding From Within Java
-
09-10-2019 - |
Pergunta
I plan on building a few programs in Java that take advantage of the ServerSocket and Socket classes. I have the code built correctly, and I can make connections properly. However, I want to make it as easy on the user as possible when it comes to making connections and servers. So, I need a method to port forward from within Java, so that my programs can build servers on a clients machine and communicate with other machines across the internet, yet the user of the program doesn't need to put in any extra effort. Is there any effective way to perform this without accessing any external programs that would need to be downloaded?
Solução
You could use this little project.
Note: client machines are usually behind NAT gateways so other machines on the internet can not access them directly.
Outras dicas
If the server is behind a NAT or a firewall, and you don't want to use a man-in-the-middle to facilitate the connection, then it's going to be pretty hard. I suggest you look into NAT hole punching, and specifically into some open-source Java implementation like Rodi.