Skip to content

Using UPnP

gcflames5 edited this page Dec 5, 2014 · 2 revisions

Universal Plug and Play (aka UPnP) is a series of network protocols that allow client-side programs to automatically port-forward. ServerInterconnet uses the weupnp library to assist with its port forwarding capabilities. By default, port forwarding is not enabled and must be called explicitly by the implementer.

To begin the port forwarding process, first create an instance of UPNPManager:

int port = 1337;
UPNPManager upnpManager = new UPNPManager(port);

Then call the discover() and map() methods:

upnpManager.discover();
upnpManager.map(); //Returns a boolean showing whether it failed/succeeded

The port is now forwarded! It is best practice to remove the port mapping when you no longer need it:

upnpManager.remove();

Clone this wiki locally