本文整理匯總了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;
}