-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSDResponder.java
executable file
·86 lines (76 loc) · 2.36 KB
/
SDResponder.java
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
//Licensed under Apache License version 2.0
//Original license LGPL
// %Z%%M%, %I%, %G%
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package freimapgsoc;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import javax.jmdns.JmDNS;
import javax.jmdns.ServiceInfo;
/**
* A sample JmDNS responder that reads a set of rendezvous service
* definitions from a file and registers them with rendezvous. It uses
* the same file format as Apple's responder. Each record consists of
* 4 lines: name, type, text, port. Empty lines and lines starting with #
* between records are ignored.
*
* @author Arthur van Hoff
* @version %I%, %G%
*/
public class SDResponder
{
/**
* Constructor.
*/
public SDResponder(JmDNS jmdns, String file) throws IOException
{
BufferedReader in = new BufferedReader(new FileReader(file));
try {
while (true) {
String ln = in.readLine();
while ((ln != null) && (ln.startsWith("#") || ln.trim().length() == 0)) {
ln = in.readLine();
}
if (ln == null) {
break;
}
String name = ln;
String type = in.readLine();
String text = in.readLine();
int port = Integer.parseInt(in.readLine());
// make sure the type is fully qualified and in the local. domain
if (!type.endsWith(".")) {
type += ".";
}
if (!type.endsWith(".local.")) {
type += "local.";
}
jmdns.registerService(
ServiceInfo.create(type, name, port, text));
}
} finally {
in.close();
}
}
/**
* Create a responder.
*/
public static void main(String argv[]) throws IOException
{
new SDResponder(JmDNS.create(), (argv.length > 0) ? argv[0] : "services.txt");
}
}