01: package bdd.search.query;
02:
03: import java.net.ServerSocket;
04: import java.io.IOException;
05: import bdd.search.EnginePrefs;
06:
07: /** Written by Tim Macinta 1997 <br>
08: * Distributed under the GNU Public License
09: * (a copy of which is enclosed with the source). <br>
10: * <br>
11: * This class provides a specialized web server that allows queries
12: * into a search database.
13: */
14: public class QueryWebServer extends Thread {
15:
16: int port = EnginePrefs.port; // the TCP port number for this server
17: EnginePrefs prefs; // preferences
18:
19: /** Starts a new QueryWebServer on the default port. */
20: public QueryWebServer() {
21: this (EnginePrefs.port, new EnginePrefs());
22: }
23:
24: /** Starts a new QueryWebServer on the specified port. */
25: public QueryWebServer(int port) {
26: this (port, new EnginePrefs());
27: }
28:
29: /** Starts a new QueryWebServer on the specified port with the given
30: * preferences. */
31: public QueryWebServer(int port, EnginePrefs prefs) {
32: this .prefs = prefs;
33: this .port = port;
34: start();
35: }
36:
37: /** This is where connections are accepted. */
38: public void run() {
39: try {
40: ServerSocket sock = new ServerSocket(port);
41: while (true) {
42: try {
43: new QueryConnection(sock.accept(), prefs);
44: } catch (IOException e) {
45: }
46: }
47: } catch (IOException e2) {
48: e2.printStackTrace();
49: System.err.println("\n\nWarning: could not bind to port "
50: + port);
51: System.err.println("The web server won't work now.\n");
52: }
53: }
54:
55: /** This is the method that is called when the server is started from
56: * the command line.
57: */
58: public static void main(String arg[]) {
59: new QueryWebServer();
60: }
61:
62: }
|