本文整理汇总了Java中javax.jmdns.ServiceInfo.getPropertyNames方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceInfo.getPropertyNames方法的具体用法?Java ServiceInfo.getPropertyNames怎么用?Java ServiceInfo.getPropertyNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jmdns.ServiceInfo
的用法示例。
在下文中一共展示了ServiceInfo.getPropertyNames方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: jsonifyService
import javax.jmdns.ServiceInfo; //导入方法依赖的package包/类
private static JSONObject jsonifyService(ServiceInfo service) throws JSONException {
JSONObject obj = new JSONObject();
String domain = service.getDomain() + ".";
obj.put("domain", domain);
obj.put("type", service.getType().replace(domain, ""));
obj.put("name", service.getName());
obj.put("port", service.getPort());
obj.put("hostname", service.getServer());
JSONArray ipv4Addresses = new JSONArray();
InetAddress[] inet4Addresses = service.getInet4Addresses();
for (int i = 0; i < inet4Addresses.length; i++) {
if (inet4Addresses[i] != null) {
ipv4Addresses.put(inet4Addresses[i].getHostAddress());
}
}
obj.put("ipv4Addresses", ipv4Addresses);
JSONArray ipv6Addresses = new JSONArray();
InetAddress[] inet6Addresses = service.getInet6Addresses();
for (int i = 0; i < inet6Addresses.length; i++) {
if (inet6Addresses[i] != null) {
ipv6Addresses.put(inet6Addresses[i].getHostAddress());
}
}
obj.put("ipv6Addresses", ipv6Addresses);
JSONObject props = new JSONObject();
Enumeration<String> names = service.getPropertyNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
props.put(name, service.getPropertyString(name));
}
obj.put("txtRecord", props);
return obj;
}