org.fourthline.cling.support.igd
Class PortMappingListener
java.lang.Object
org.fourthline.cling.registry.DefaultRegistryListener
org.fourthline.cling.support.igd.PortMappingListener
- All Implemented Interfaces:
- 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
- Author:
- Christian Bauer
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
IGD_DEVICE_TYPE
public static final DeviceType IGD_DEVICE_TYPE
CONNECTION_DEVICE_TYPE
public static final DeviceType CONNECTION_DEVICE_TYPE
IP_SERVICE_TYPE
public static final ServiceType IP_SERVICE_TYPE
PPP_SERVICE_TYPE
public static final ServiceType PPP_SERVICE_TYPE
portMappings
protected PortMapping[] portMappings
activePortMappings
protected Map<Service,List<PortMapping>> activePortMappings
PortMappingListener
public PortMappingListener(PortMapping portMapping)
PortMappingListener
public PortMappingListener(PortMapping[] portMappings)
deviceAdded
public void deviceAdded(Registry registry,
Device device)
- Overrides:
deviceAdded
in class DefaultRegistryListener
deviceRemoved
public void deviceRemoved(Registry registry,
Device device)
- Overrides:
deviceRemoved
in class DefaultRegistryListener
beforeShutdown
public void beforeShutdown(Registry registry)
- Specified by:
beforeShutdown
in interface RegistryListener
- Overrides:
beforeShutdown
in class DefaultRegistryListener
discoverConnectionService
protected Service discoverConnectionService(Device device)
handleFailureMessage
protected void handleFailureMessage(String s)
Copyright © 2013 4th Line GmbH, Switzerland. All Rights Reserved.