当前位置: 首页>>代码示例>>Java>>正文


Java PortMappingEntry类代码示例

本文整理汇总了Java中org.bitlet.weupnp.PortMappingEntry的典型用法代码示例。如果您正苦于以下问题:Java PortMappingEntry类的具体用法?Java PortMappingEntry怎么用?Java PortMappingEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PortMappingEntry类属于org.bitlet.weupnp包,在下文中一共展示了PortMappingEntry类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addPortMapping

import org.bitlet.weupnp.PortMappingEntry; //导入依赖的package包/类
private void addPortMapping(int port, String description) throws IOException, SAXException
{
	final PortMappingEntry portMapping = new PortMappingEntry();
	final InetAddress localAddress = _activeGW.getLocalAddress();
	
	// Attempt to re-map
	if (_activeGW.getSpecificPortMappingEntry(port, PROTOCOL, portMapping))
	{
		_activeGW.deletePortMapping(port, PROTOCOL);
	}
	
	if (_activeGW.addPortMapping(port, port, localAddress.getHostAddress(), PROTOCOL, description))
	{
		_log.log(Level.INFO, "Mapping successfull on [" + localAddress.getHostAddress() + ":" + port + "]");
	}
	else
	{
		_log.log(Level.INFO, "Mapping failed on [" + localAddress.getHostAddress() + ":" + port + "] - Already mapped?");
	}
}
 
开发者ID:Zoey76,项目名称:L2J_LoginServer,代码行数:21,代码来源:UPnPService.java

示例2: isPortMapped

import org.bitlet.weupnp.PortMappingEntry; //导入依赖的package包/类
public boolean isPortMapped(int port) throws IOException, SAXException
{
	if (activeGW != null)
	{
		PortMappingEntry portMapping = new PortMappingEntry();
		return activeGW.getSpecificPortMappingEntry(port,"TCP",portMapping);
	}
	return false;
}
 
开发者ID:BitcoinAuthenticator,项目名称:Wallet,代码行数:10,代码来源:UpNp.java

示例3: run

import org.bitlet.weupnp.PortMappingEntry; //导入依赖的package包/类
/**
 * args:<br>
 * [0] - port number
 * @param args
 * @throws Exception
 */
public void run(String[] args) throws Exception{
	PORT = Integer.parseInt(args[0]);
	boolean LIST_ALL_MAPPINGS = false;
	addLogLine("Starting weupnp");
	GatewayDiscover gatewayDiscover = new GatewayDiscover();
	addLogLine("Looking for Gateway Devices...");
	Map<InetAddress, GatewayDevice> gateways = gatewayDiscover.discover();
	if (gateways.isEmpty()) {
		addLogLine("No gateways found");
		addLogLine("Stopping weupnp");
		return;
	}
	addLogLine(gateways.size()+" gateway(s) found\n");
	int counter=0;
	for (GatewayDevice gw: gateways.values()) {
		counter++;
		addLogLine("Listing gateway details of device #" + counter+
				"\n\tFriendly name: " + gw.getFriendlyName()+
				"\n\tPresentation URL: " + gw.getPresentationURL()+
				"\n\tModel name: " + gw.getModelName()+
				"\n\tModel number: " + gw.getModelNumber()+
				"\n\tLocal interface address: " + gw.getLocalAddress().getHostAddress()+"\n");
	}
	// Choose the first active gateway for the tests
	activeGW = gatewayDiscover.getValidGateway();
	if (null != activeGW) {
		addLogLine("Using gateway: " + activeGW.getFriendlyName());
	} else {
		addLogLine("No active gateway device found");
		addLogLine("Stopping weupnp");
		return;
	}
	
	/* get local and external IPs*/
	InetAddress localAddress = activeGW.getLocalAddress();
	localIPAddress = activeGW.getLocalAddress().toString();
	addLogLine("Using local address: "+ localAddress.getHostAddress());
	externalIPAddress = activeGW.getExternalIPAddress();
	addLogLine("External address: "+ externalIPAddress);
	
	/* Check if port is mapped */
	addLogLine("Attempting to map port " + PORT);
	PortMappingEntry portMapping = new PortMappingEntry();
	if (activeGW.getSpecificPortMappingEntry(PORT,"TCP",portMapping)) {
		addLogLine("Port " + PORT + " is already mapped. Aborting test.");
		return;
	} else {
		addLogLine("Mapping free. Sending port mapping request for port " + PORT);
		if (activeGW.addPortMapping(PORT, PORT,localAddress.getHostAddress(), "TCP", "BTCAuthenticator_Mapping")) {
			addLogLine("Mapping SUCCESSFUL"); 
		}
		else
			addLogLine("Port mapping attempt failed"); 
	} 
}
 
开发者ID:BitcoinAuthenticator,项目名称:Wallet,代码行数:62,代码来源:UpNp.java

示例4: enableNATInboundConnections

import org.bitlet.weupnp.PortMappingEntry; //导入依赖的package包/类
protected void enableNATInboundConnections() throws Exception {
    GatewayDiscover discover = new GatewayDiscover();
    LOGGER.debug("Looking for gateway devices");
    discover.discover();
    final GatewayDevice natDevice = discover.getValidGateway();
    if (null != natDevice) {
      LOGGER.debug("Gateway device found {} {} ", natDevice.getModelName(), natDevice.getModelDescription());
    } else {
      LOGGER.debug("No valid gateway device found, doing nothing.");
      return;
    }

//    String externalIPAddress = natDevice.getExternalIPAddress();
//    LOGGER.debug("Our external address is {}", externalIPAddress);
//    server1.setListeningAddress(externalIPAddress);

    final int localPortToMap=getListeningPort();
    LOGGER.debug("Querying device to see if a mapping for port {} already exists", localPortToMap);

    PortMappingEntry portMapping = new PortMappingEntry();
    if (natDevice.getSpecificPortMappingEntry(localPortToMap, "TCP", portMapping)) {
      LOGGER.error("Port {} was already mapped by {}. Aborting...", localPortToMap, portMapping.getPortMappingDescription()); //TODO Maybe we should retry with another port number. Do not forget to update the local gossip info with the new port
    } else {
      LOGGER.debug("External port {} is available, sending mapping request", localPortToMap);
      InetAddress localAddress = natDevice.getLocalAddress();
      if (natDevice.addPortMapping(localPortToMap, localPortToMap, localAddress.getHostAddress(), "TCP", getClass().getName())) {
        LOGGER.info("Port mapping successfull");
        Runtime.getRuntime().addShutdownHook(new Thread(){
          public void run() {
            try {
              LOGGER.debug("deleting port mapping {}", localPortToMap);
              natDevice.deletePortMapping(localPortToMap, "TCP");
            } catch (Exception e) {
              e.printStackTrace();
            }
          };
        });
      } else {
        LOGGER.error("Port mapping failed");
      }
    }
  }
 
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:43,代码来源:NetworkServer.java

示例5: test

import org.bitlet.weupnp.PortMappingEntry; //导入依赖的package包/类
@Test
public void test() throws Exception {
	GatewayDiscover discover = new GatewayDiscover();
	System.out.println("Looking for Gateway Devices");
	discover.discover();
	GatewayDevice d = discover.getValidGateway();

	if (null != d) {
		System.out.println("Gateway device found "+d.getModelName()+" " +d.getModelDescription());
	} else {
		System.out.println("No valid gateway device found.");
		return;
	}

	InetAddress localAddress = d.getLocalAddress();
	System.out.println("Using local address: "+ localAddress);
	String externalIPAddress = d.getExternalIPAddress();
	System.out.println("External address: "+ externalIPAddress);
	PortMappingEntry portMapping = new PortMappingEntry();
	
	System.out.println("Attempting to map port {0}" + SAMPLE_PORT);
	System.out.println("Querying device to see if mapping for port {0} already exists"+	SAMPLE_PORT);

	if (!d.getSpecificPortMappingEntry(SAMPLE_PORT, "TCP", portMapping)) {
		System.out.println("Sending port mapping request");

		if (d.addPortMapping(SAMPLE_PORT, SAMPLE_PORT, localAddress.getHostAddress(), "TCP", "libminiupnpc")) {
			System.out.println("Mapping succesful: waiting {0} seconds before removing mapping." + WAIT_TIME);

			Thread.sleep(1000 * WAIT_TIME);
			d.deletePortMapping(SAMPLE_PORT, "TCP");

			System.out.println("Port mapping removed");
			System.out.println("Test SUCCESSFUL");
		} else {
			System.out.println("Port mapping failed");
			fail();
		}

	} else {
		System.out.println("Port was already mapped. Aborting test.");
		fail();
	}

	System.out.println("Stopping weupnp");
}
 
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:47,代码来源:WEUPnPTest.java

示例6: portmap

import org.bitlet.weupnp.PortMappingEntry; //导入依赖的package包/类
private void portmap(GatewayDevice d, int port) {
	String localAddress = d.getLocalAddress().getHostAddress();
	String externalIPAddress;
	try {
		externalIPAddress = d.getExternalIPAddress();
	} catch (IOException | SAXException e1) {
		Util.log(this, "External address: (unknown)");
		return;
	}

	for (int i = 0; i < 10; ++i) {
		int externalport = port + 10 * i;
		String portMappingStr = localAddress + ":" + port + " <-> " + externalIPAddress + ":"
				+ externalport;
		PortMappingEntry portMapping = new PortMappingEntry();
		try {
			if (!d.getSpecificPortMappingEntry(externalport, "TCP", portMapping)) {
				Util.log(this, "Attempting to map port: " + portMappingStr);
				if (d.addPortMapping(externalport, port, localAddress, "TCP", "test")) {
					Util.log(this, "Mapping successful!");
					break;

				} else {
					Util.log(this, "Mapping failed...");
				}
			} else {
				Util.log(this, "Port mapping entry already exists: " + portMappingStr);
				int portMappedLocalPort = portMapping.getInternalPort();
				String portMappedLocalAddress = portMapping.getInternalClient();
				if (!portMappedLocalAddress.equals(localAddress)) {
					Util.log(this, "Error: local IP in port map entry (" + portMappedLocalAddress
							+ ") does not match local IP (" + localAddress + ")!");
				} else if (portMappedLocalPort != port) {
					Util.log(this, "Error: local port in port map entry (" + portMappedLocalPort
							+ ") does not match local port (" + port + ")!");
				} else {
					break;
				}
			}
		} catch (IOException | SAXException e) {
			e.printStackTrace();
		}
	}
}
 
开发者ID:tobiasschulz,项目名称:voipcall,代码行数:45,代码来源:UpnpClient.java


注:本文中的org.bitlet.weupnp.PortMappingEntry类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。