-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTester.java
More file actions
104 lines (93 loc) · 3.85 KB
/
Tester.java
File metadata and controls
104 lines (93 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import java.net.InetAddress;
import org.xbill.DNS.Name;
import org.xbill.DNS.Record;
import org.xbill.DNS.Type;
import org.xbill.mDNS.Lookup;
import org.xbill.mDNS.MulticastDNSService;
import org.xbill.mDNS.ServiceInstance;
import org.xbill.mDNS.ServiceName;
public class Tester
{
/**
* @param args
*/
public static void main(final String[] args)
{
int priority = 10;
int weight = 10;
int port = 8080;
String ucn = "urn:smpte:ucn:org.smpte.st2071:device_v1.0";
String ucnPTRName = "_org.smpte.st2071:device_v1.0._sub._mdc._tcp";
// String ucnPTRName = "_mdc._tcp";
String domain = "local.";
String hostname = "TestHost";
try
{
MulticastDNSService service = new MulticastDNSService();
Name fqn = new Name(hostname + "." + (domain.endsWith(".") ? domain : domain + "."));
ServiceName srvName = new ServiceName(hostname + "." + ucnPTRName + "." + (domain.endsWith(".") ? domain : domain + "."));
ServiceInstance serviceInstance = new ServiceInstance(srvName, priority, weight, port, fqn, new InetAddress[] {InetAddress.getByName("192.168.1.74")}, "textvers=1", "rn=urn:smpte:udn:local:id=1234567890ABCDEF", "proto=mdcp", "path=/Device");
ServiceInstance registeredService = service.register(serviceInstance);
if (registeredService != null)
{
System.out.println("Services Successfully Registered: \n\t" + registeredService);
} else
{
boolean hostnameResolves = false;
Lookup lookup = new Lookup(fqn);
Record[] rrs = lookup.lookupRecords();
if ((rrs != null) && (rrs.length > 0))
{
outer:
for (Record rr : rrs)
{
switch (rr.getType())
{
case Type.A:
case Type.A6:
case Type.AAAA:
case Type.DNAME:
case Type.CNAME:
case Type.PTR:
if (rr.getName().equals(fqn))
{
hostnameResolves = true;
break outer;
}
break;
}
}
}
System.err.println("Services Registration for UCN \"" + ucn + "\" in domain \"" + domain + "\" Failed!");
if (hostnameResolves)
{
System.err.println("Hostname \"" + fqn + "\" can be resolved.");
} else
{
System.err.println("Hostname \"" + fqn + "\" cannot be resolved!");
}
}
while (true)
{
Thread.sleep(10);
if (System.in.read() == 'q')
{
break;
}
}
if (service.unregister(registeredService))
{
System.out.println("Services Successfully Unregistered: \n\t" + registeredService);
} else
{
System.err.println("Services was not Unregistered: \n\t" + registeredService);
}
service.close();
System.exit(0);
} catch (Exception e)
{
System.err.println("Error Registering Capability \"" + ucn + "\" for Discovery - " + e.getMessage());
e.printStackTrace(System.err);
}
}
}