本文整理汇总了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));
}
示例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;
}
示例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);
}
}
示例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..." );
}
}
示例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);
}
}
示例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());
}
}
示例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);
}
示例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, "");
}
示例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();
}
}