public class PortMappingListener
extends org.fourthline.cling.registry.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<org.fourthline.cling.model.meta.Service,List<PortMapping>> |
activePortMappings |
static org.fourthline.cling.model.types.DeviceType |
CONNECTION_DEVICE_TYPE |
static org.fourthline.cling.model.types.DeviceType |
IGD_DEVICE_TYPE |
static org.fourthline.cling.model.types.ServiceType |
IP_SERVICE_TYPE |
protected PortMapping[] |
portMappings |
static org.fourthline.cling.model.types.ServiceType |
PPP_SERVICE_TYPE |
Constructor and Description |
---|
PortMappingListener(PortMapping portMapping) |
PortMappingListener(PortMapping[] portMappings) |
Modifier and Type | Method and Description |
---|---|
void |
beforeShutdown(org.fourthline.cling.registry.Registry registry) |
void |
deviceAdded(org.fourthline.cling.registry.Registry registry,
org.fourthline.cling.model.meta.Device device) |
void |
deviceRemoved(org.fourthline.cling.registry.Registry registry,
org.fourthline.cling.model.meta.Device device) |
protected org.fourthline.cling.model.meta.Service |
discoverConnectionService(org.fourthline.cling.model.meta.Device device) |
protected void |
handleFailureMessage(String s) |
public static final org.fourthline.cling.model.types.DeviceType IGD_DEVICE_TYPE
public static final org.fourthline.cling.model.types.DeviceType CONNECTION_DEVICE_TYPE
public static final org.fourthline.cling.model.types.ServiceType IP_SERVICE_TYPE
public static final org.fourthline.cling.model.types.ServiceType PPP_SERVICE_TYPE
protected PortMapping[] portMappings
protected Map<org.fourthline.cling.model.meta.Service,List<PortMapping>> activePortMappings
public PortMappingListener(PortMapping portMapping)
public PortMappingListener(PortMapping[] portMappings)
public void deviceAdded(org.fourthline.cling.registry.Registry registry, org.fourthline.cling.model.meta.Device device)
deviceAdded
in class org.fourthline.cling.registry.DefaultRegistryListener
public void deviceRemoved(org.fourthline.cling.registry.Registry registry, org.fourthline.cling.model.meta.Device device)
deviceRemoved
in class org.fourthline.cling.registry.DefaultRegistryListener
public void beforeShutdown(org.fourthline.cling.registry.Registry registry)
beforeShutdown
in interface org.fourthline.cling.registry.RegistryListener
beforeShutdown
in class org.fourthline.cling.registry.DefaultRegistryListener
protected org.fourthline.cling.model.meta.Service discoverConnectionService(org.fourthline.cling.model.meta.Device device)
protected void handleFailureMessage(String s)
Copyright © 2016 4th Line GmbH, Switzerland. All rights reserved.