简体   繁体   中英

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?

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);

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/

UPnP protocol can handle the automatic port forwarding. Try this library (Cling - Java/Android UPnP library and tools): http://4thline.org/projects/cling/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM