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


Java Action.getControlStatus方法代码示例

本文整理汇总了Java中org.cybergarage.upnp.Action.getControlStatus方法的典型用法代码示例。如果您正苦于以下问题:Java Action.getControlStatus方法的具体用法?Java Action.getControlStatus怎么用?Java Action.getControlStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.cybergarage.upnp.Action的用法示例。


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

示例1: addMapping

import org.cybergarage.upnp.Action; //导入方法依赖的package包/类
/**
 *  This always requests that the external port == the internal port, for now.
 *  Blocking!
 */
private boolean addMapping(String protocol, int port, String description, ForwardPort fp) {
	if(isDisabled || !isNATPresent() || _router == null) {
                       _log.error("Can't addMapping: " + isDisabled + " " + isNATPresent() + " " + _router);
		return false;
               }
	
	// Just in case...
               // this confuses my linksys? - zzz
	//removeMapping(protocol, port, fp, true);
	
	Action add = _service.getAction("AddPortMapping");
	if(add == null) {
                   if (_serviceLacksAPM) {
		if (_log.shouldLog(Log.WARN))
		    _log.warn("Couldn't find AddPortMapping action!");
	    } else {	
		_serviceLacksAPM = true;
		_log.logAlways(Log.WARN, "UPnP device does not support port forwarding");
	    }
	    return false;
	}
	    
	
	add.setArgumentValue("NewRemoteHost", "");
	add.setArgumentValue("NewExternalPort", port);
	// bugfix, see below for details
	String intf = _router.getInterfaceAddress();
	String us = getOurAddress(intf);
	if (_log.shouldLog(Log.WARN) && !us.equals(intf))
		_log.warn("Requesting port forward to " + us + ':' + port +
		          " when cybergarage wanted " + intf);
	add.setArgumentValue("NewInternalClient", us);
	add.setArgumentValue("NewInternalPort", port);
	add.setArgumentValue("NewProtocol", protocol);
	add.setArgumentValue("NewPortMappingDescription", description);
	add.setArgumentValue("NewEnabled","1");
	add.setArgumentValue("NewLeaseDuration", 0);
	
	boolean rv = add.postControlAction();
	if(rv) {
		synchronized(lock) {
			portsForwarded.add(fp);
		}
	}

	int level = rv ? Log.INFO : Log.WARN;
	if (_log.shouldLog(level)) {
		StringBuilder buf = new StringBuilder();
		buf.append("AddPortMapping result for ").append(protocol).append(" port ").append(port);
		// Not sure which of these has the good info
		UPnPStatus status = add.getStatus();
		if (status != null)
		    buf.append(" Status: ").append(status.getCode()).append(' ').append(status.getDescription());
		status = add.getControlStatus();
		if (status != null)
		    buf.append(" ControlStatus: ").append(status.getCode()).append(' ').append(status.getDescription());
		_log.log(level, buf.toString());
	}

	// TODO if port is busy, retry with wildcard external port ??
	// from spec:
	// 402 Invalid Args See UPnP Device Architecture section on Control.
	// 501 Action Failed See UPnP Device Architecture section on Control.
	// 715 WildCardNotPermittedInSrcIP The source IP address cannot be wild-carded
	// 716 WildCardNotPermittedInExtPort The external port cannot be wild-carded
	// 718 ConflictInMappingEntry The port mapping entry specified conflicts with a mapping assigned previously to another client
	// 724 SamePortValuesRequired Internal and External port values must be the same
	// 725 OnlyPermanentLeasesSupported The NAT implementation only supports permanent lease times on port mappings
	// 726 RemoteHostOnlySupportsWildcard RemoteHost must be a wildcard and cannot be a specific IP address or DNS name
	// 727 ExternalPortOnlySupportsWildcard ExternalPort must be a wildcard and cannot be a specific port value

	// TODO return error code and description for display

	return rv;
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:80,代码来源:UPnP.java


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