}
if (intf == null) {
intf = InetAddress.getLocalHost();
}
JmDNS jmdns = JmDNS.create(intf);
if ((argc == 0) || ((argc >= 1) && "-browse".equals(argv[0]))) {
new Browser(jmdns);
for (int i = 2 ; i < argc ; i++) {
jmdns.registerServiceType(argv[i]);
}
} else if ((argc == 1) && "-bt".equals(argv[0])) {
jmdns.addServiceTypeListener(new SampleListener());
} else if ((argc == 3) && "-bs".equals(argv[0])) {
jmdns.addServiceListener(argv[1] + "." + argv[2], new SampleListener());
} else if ((argc > 4) && "-rs".equals(argv[0])) {
String type = argv[2] + "." + argv[3];
String name = argv[1];
Hashtable props = null;
for (int i = 5 ; i < argc ; i++) {
int j = argv[i].indexOf('=');
if (j < 0) {
throw new RuntimeException("not key=val: " + argv[i]);
}
if (props == null) {
props = new Hashtable();
}
props.put(argv[i].substring(0, j), argv[i].substring(j+1));
}
jmdns.registerService(ServiceInfo.create(type, name, Integer.parseInt(argv[4]), 0, 0, props));
// This while loop keeps the main thread alive
while (true) {
try {
Thread.sleep(Integer.MAX_VALUE);