Klasse PortMappingListener

java.lang.Object
org.jupnp.registry.DefaultRegistryListener
org.jupnp.support.igd.PortMappingListener
Alle implementierten Schnittstellen:
RegistryListener

public class PortMappingListener extends DefaultRegistryListener
Maintains UPnP port mappings on an InternetGatewayDevice automatically.

This listener will wait for discovered devices which support either WANIPConnection or the WANPPPConnection service. As soon as any such service is discovered, the desired port mapping will be created. When the UPnP service is shutting down, all previously established port mappings with all services will be deleted.

The following listener maps external WAN TCP port 8123 to internal host 10.0.0.2:


 upnpService.getRegistry()
         .addListener(newPortMappingListener(newPortMapping(8123, "10.0.0.2", PortMapping.Protocol.TCP)));
 

If all you need from the Cling UPnP stack is NAT port mapping, use the following idiom:


 UpnpService upnpService = new UpnpServiceImpl(
     new PortMappingListener(new PortMapping(8123, "10.0.0.2", PortMapping.Protocol.TCP))
 );
 <p/>
 upnpService.getControlPoint().search(new STAllHeader()); // Search for all devices
 <p/>
 upnpService.shutdown(); // When you no longer need the port mapping
 
Autor:
Christian Bauer, Amit Kumar Mondal - Code Refactoring