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


Java ServiceInfo.create方法代码示例

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


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

示例1: addService

import javax.jmdns.ServiceInfo; //导入方法依赖的package包/类
/**
 * Publish a zeroconf service.
 *
 * Should actually provide a return value here, so the user can see the
 * actually published name.
 *
 * @param name : english readable name for the service
 * @param type : zeroconf service type, e.g. _ros-master._tcp
 * @param domain : domain to advertise on (usually 'local')
 * @param port : port number
 * @param description :
 */
public void addService(String name, String type, String domain, int port, String description) {
    String full_service_type = type + "." + domain + ".";
    logger.println("Registering service: " + full_service_type);
    String service_key = "description"; // Max 9 chars
    HashMap<String, byte[]> properties = new HashMap<String, byte[]>();
    properties.put(service_key,description.getBytes());
    ServiceInfo service_info = ServiceInfo.create(full_service_type, name, port, 0, 0, true, properties);
    // we need much better logic here to handle duplications.
    if ( services.add(service_info) ) {
        try {
            jmmdns.registerService(service_info);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // this is broken - it adds it, but fails to resolve it on other systems
    // https://sourceforge.net/tracker/?func=detail&aid=3435220&group_id=93852&atid=605791
    // services.add(ServiceInfo.create(service_type, service_name, service_port, 0, 0, true, text));
}
 
开发者ID:rosalfred,项目名称:smarthome_network_zeroconf,代码行数:33,代码来源:Zeroconf.java

示例2: register

import javax.jmdns.ServiceInfo; //导入方法依赖的package包/类
public ServiceInfo register(String type, String domain, String name, int port, JSONObject props) throws JSONException, IOException {

            HashMap<String, String> txtRecord = new HashMap<String, String>();
            if (props != null) {
                Iterator<String> iter = props.keys();
                while (iter.hasNext()) {
                    String key = iter.next();
                    txtRecord.put(key, props.getString(key));
                }
            }

            ServiceInfo aService = null;
            for (JmDNS publisher : publishers) {
                ServiceInfo service = ServiceInfo.create(type + domain, name, port, 0, 0, txtRecord);
                try {
                    publisher.registerService(service);
                    aService = service;
                } catch (IOException e) {
                    Log.e(TAG, e.getMessage(), e);
                }
            }
            // returns only one of the ServiceInfo instances!
            return aService;
        }
 
开发者ID:becvert,项目名称:cordova-plugin-zeroconf,代码行数:25,代码来源:ZeroConf.java

示例3: init

import javax.jmdns.ServiceInfo; //导入方法依赖的package包/类
/**
 * Initialize and run the mDNS Service discovery. Will start advertising
 */
private void init() {
    try {
        jmDNS = JmDNS.create();
        serviceInfo = ServiceInfo.create("_http._tcp.local.",
                "Shooflers-Dashboard", port,
                "An awesome webapp to handle your monitor dashboards");
        jmDNS.registerService(serviceInfo);
    } catch (IOException e) {
        LOGGER.error("Couldn't initialize mDNS for service discovery.", e);
        throw new IllegalStateException(e);
    }
}
 
开发者ID:resourcepool,项目名称:dashboard,代码行数:16,代码来源:ServiceDiscovery.java

示例4: registerService

import javax.jmdns.ServiceInfo; //导入方法依赖的package包/类
/**
   * Register a local service provider.
* @param protocol The protocol identifying the service type.
* @param serviceName The unique name of the service provider.
   * @param provider The provider which handles the service requests.
* @param properties Properties.
* @return a new service reference for successful registration and null otherwise.
   */
  public <ProtocolType> ServiceRef registerService( final Class<ProtocolType> protocol, final String serviceName, final ProtocolType provider, final Map<String,Object> properties ) {
properties.put( ServiceRef.SERVICE_KEY, serviceName );
      
      final String serviceType = getDefaultType( protocol );

try {
          if ( _rpcServer == null ) {
              _rpcServer = new RpcServer( MESSAGE_CODER );
              _rpcServer.start();
          }
            
	int port = _rpcServer.getPort();
	
	// add the service to the RPC Server
	_rpcServer.addHandler( serviceName, protocol, provider );
	
	// advertise the service to the world
	final String bonjourType = ServiceRef.getFullType( serviceType );
	final ServiceInfo info = ServiceInfo.create( bonjourType, serviceName, port, 0, 0, properties );
	_bonjour.registerService( info );
	return new ServiceRef( info );
}
catch( Exception exception ) {
	throw new ServiceException( exception, "Exception while attempting to register a service..." );
}
  }
 
开发者ID:openxal,项目名称:openxal,代码行数:35,代码来源:ServiceDirectory.java

示例5: start

import javax.jmdns.ServiceInfo; //导入方法依赖的package包/类
@Override
public void start() {

    Utils.debugLog(TAG, "Preparing to start Bonjour service.");
    sendBroadcast(SwapService.EXTRA_STARTING);

    /*
     * a ServiceInfo can only be registered with a single instance
     * of JmDNS, and there is only ever a single LocalHTTPD port to
     * advertise anyway.
     */
    if (pairService != null || jmdns != null)
        clearCurrentMDNSService();
    String repoName = Preferences.get().getLocalRepoName();
    HashMap<String, String> values = new HashMap<>();
    values.put("path", "/fdroid/repo");
    values.put("name", repoName);
    values.put("fingerprint", FDroidApp.repo.fingerprint);
    String type;
    if (Preferences.get().isLocalRepoHttpsEnabled()) {
        values.put("type", "fdroidrepos");
        type = "_https._tcp.local.";
    } else {
        values.put("type", "fdroidrepo");
        type = "_http._tcp.local.";
    }
    try {
        Utils.debugLog(TAG, "Starting bonjour service...");
        pairService = ServiceInfo.create(type, repoName, FDroidApp.port, 0, 0, values);
        jmdns = JmDNS.create(InetAddress.getByName(FDroidApp.ipAddressString));
        jmdns.registerService(pairService);
        setConnected(true);
        Utils.debugLog(TAG, "... Bounjour service started.");
    } catch (IOException e) {
        Log.e(TAG, "Error while registering jmdns service", e);
        setConnected(false);
    }
}
 
开发者ID:nutellarlz,项目名称:AppHub,代码行数:39,代码来源:BonjourBroadcast.java

示例6: registerService

import javax.jmdns.ServiceInfo; //导入方法依赖的package包/类
/**
 * @{inheritDoc}
 */
public void registerService(ServiceDescription description) {
	ServiceInfo serviceInfo = ServiceInfo.create(description.serviceType, description.serviceName, description.servicePort,
			0, 0, description.serviceProperties);		
	try {
		logger.debug("Registering new service " + description.serviceType + " at port " + 
				String.valueOf(description.servicePort));
		jmdns.registerService(serviceInfo);
	} catch (IOException e) {
		logger.error(e.getMessage());
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:15,代码来源:DiscoveryServiceImpl.java

示例7: unregisterService

import javax.jmdns.ServiceInfo; //导入方法依赖的package包/类
/**
 * @{inheritDoc}
 */
public void unregisterService(ServiceDescription description) {
	ServiceInfo serviceInfo = ServiceInfo.create(description.serviceType, description.serviceName, description.servicePort,
			0, 0, description.serviceProperties);
	logger.debug("Unregistering service " + description.serviceType + " at port " + 
			String.valueOf(description.servicePort));
	jmdns.unregisterService(serviceInfo);
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:11,代码来源:DiscoveryServiceImpl.java

示例8: createServiceInfo

import javax.jmdns.ServiceInfo; //导入方法依赖的package包/类
protected ServiceInfo createServiceInfo(String name, Map map) {
    int port = MapHelper.getInt(map, "port", 0);

    String type = getType();

    if (LOG.isDebugEnabled()) {
        LOG.debug("Registering service type: " + type + " name: " + name + " details: " + map);
    }
    return ServiceInfo.create(type, name + "." + type, port, weight, priority, "");
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:11,代码来源:ZeroconfDiscoveryAgent.java

示例9: registerServices

import javax.jmdns.ServiceInfo; //导入方法依赖的package包/类
public void registerServices() {
	try {
		// Register a service
		ServiceInfo serviceInfo = ServiceInfo.create("_http._tcp.local.", "HomeAutomation", 8080,
				"path=index.html");
		registerService(serviceInfo);

		ServiceInfo mqttService = ServiceInfo.create("_mqtt._tcp.local.", "HomeAutomation", 1883,
				"/sensordata");
		registerService(mqttService);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:comdata,项目名称:HomeAutomation,代码行数:16,代码来源:MDNSService.java


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