public class PortMappingListener extends DefaultRegistryListener
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
Modifier and Type | Field and Description |
---|---|
protected Map<Service,List<PortMapping>> |
activePortMappings |
static DeviceType |
CONNECTION_DEVICE_TYPE |
static DeviceType |
IGD_DEVICE_TYPE |
static ServiceType |
IP_SERVICE_TYPE |
protected PortMapping[] |
portMappings |
static ServiceType |
PPP_SERVICE_TYPE |
Constructor and Description |
---|
PortMappingListener(PortMapping portMapping) |
PortMappingListener(PortMapping[] portMappings) |
Modifier and Type | Method and Description |
---|---|
void |
beforeShutdown(Registry registry) |
void |
deviceAdded(Registry registry,
Device device) |
void |
deviceRemoved(Registry registry,
Device device) |
protected Service |
discoverConnectionService(Device device) |
protected void |
handleFailureMessage(String s) |
afterShutdown, localDeviceAdded, localDeviceRemoved, remoteDeviceAdded, remoteDeviceDiscoveryFailed, remoteDeviceDiscoveryStarted, remoteDeviceRemoved, remoteDeviceUpdated
public static final DeviceType IGD_DEVICE_TYPE
public static final DeviceType CONNECTION_DEVICE_TYPE
public static final ServiceType IP_SERVICE_TYPE
public static final ServiceType PPP_SERVICE_TYPE
protected PortMapping[] portMappings
protected Map<Service,List<PortMapping>> activePortMappings
public PortMappingListener(PortMapping portMapping)
public PortMappingListener(PortMapping[] portMappings)
public void deviceAdded(Registry registry, Device device)
deviceAdded
in class DefaultRegistryListener
public void deviceRemoved(Registry registry, Device device)
deviceRemoved
in class DefaultRegistryListener
public void beforeShutdown(Registry registry)
beforeShutdown
in interface RegistryListener
beforeShutdown
in class DefaultRegistryListener
protected void handleFailureMessage(String s)
Copyright © 2015 4th Line GmbH, Switzerland. All rights reserved.