How to port forward automatically in java?

依然范特西╮ 提交于 2019-12-09 19:42:02

问题


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?


回答1:


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



回答2:


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/




回答3:


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



来源:https://stackoverflow.com/questions/31951467/how-to-port-forward-automatically-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!