Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to port forward automatically in java?

I know that bit torrent clients use automatic port forwarding (Port forwarding with having to configure the router) so that they can connect to each other. I want the users in my application to be able to host a server without having to configure the router. So I was wondering how you would do so in java?

like image 366
sazzy4o Avatar asked Aug 23 '26 20:08

sazzy4o


2 Answers

You can use UPnP (Universal Plug and Play) port forwarding. One library mentioned is Cling, but there's much simpler library - WaifUPnP, which allows you to forward a port with just one line like:

UPnP.openTCP(portnumber);
like image 74
Kotauskas Avatar answered Aug 26 '26 09:08

Kotauskas


UPnP is your friend. It is a standardized method which allows automatically configuring routers to forward ports. There are a couple of different ways to do it. One package that supports UPnP under Java is Cling. http://4thline.org/projects/cling/

like image 25
Tripp Kinetics Avatar answered Aug 26 '26 10:08

Tripp Kinetics



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!