简体   繁体   English

如何在java中自动转发?

[英]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.我知道 bit torrent 客户端使用自动端口转发(必须配置路由器的端口转发),以便它们可以相互连接。 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?所以我想知道你会如何在java中做到这一点?

You can use UPnP (Universal Plug and Play) port forwarding.您可以使用 UPnP(通用即插即用)端口转发。 One library mentioned is Cling , but there's much simpler library - WaifUPnP , which allows you to forward a port with just one line like:提到的一个库是Cling ,但有更简单的库 - WaifUPnP ,它允许您只用一行来转发端口,例如:

UPnP.openTCP(portnumber);

UPnP is your friend. UPnP 是您的朋友。 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.在 Java 下支持 UPnP 的一个包是 Cling。 http://4thline.org/projects/cling/ http://4thline.org/projects/cling/

UPnP protocol can handle the automatic port forwarding. UPnP 协议可以处理自动端口转发。 Try this library (Cling - Java/Android UPnP library and tools): http://4thline.org/projects/cling/试试这个库(Cling - Java/Android UPnP 库和工具):http: //4thline.org/projects/cling/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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