01: /*
02: * This file is part of the QuickServer library
03: * Copyright (C) 2003-2005 QuickServer.org
04: *
05: * Use, modification, copying and distribution of this software is subject to
06: * the terms and conditions of the GNU Lesser General Public License.
07: * You should have received a copy of the GNU LGP License along with this
08: * library; if not, you can download a copy from <http://www.quickserver.org/>.
09: *
10: * For questions, suggestions, bug-reports, enhancement-requests etc.
11: * visit http://www.quickserver.org
12: *
13: */
14:
15: package dateserver;
16:
17: import org.quickserver.net.*;
18: import org.quickserver.net.server.*;
19:
20: import java.io.*;
21: import java.util.logging.*;
22:
23: /**
24: * Example demonstrates how to send java object over the socket.
25: */
26: public class DateServer {
27: public static String VER = "1.0";
28:
29: public static void main(String s[]) {
30: String cmdHandle = "dateserver.CommandHandler";
31: String objHandle = "dateserver.ObjectHandler";
32: String auth = null;
33:
34: QuickServer myServer = new QuickServer(cmdHandle);
35: myServer.setClientAuthenticationHandler(auth);
36: myServer.setPort(125);
37: myServer.setName("Date Server v " + VER);
38: if (getQuickServerVersion() >= 1.2) {
39: System.out.println("Using 1.2 feature");
40: myServer.setClientObjectHandler(objHandle);
41:
42: //reduce info to Console
43: myServer.setConsoleLoggingToMicro();
44: }
45:
46: //setup logger to log to file
47: Logger logger = null;
48: FileHandler txtLog = null;
49: File log = new File("./log/");
50: if (!log.canRead())
51: log.mkdir();
52: try {
53: logger = Logger.getLogger("");
54: logger.setLevel(Level.FINEST);
55:
56: logger = Logger.getLogger("dateserver");
57: logger.setLevel(Level.FINEST);
58: txtLog = new FileHandler("log/DateServer.txt");
59: //reduce info
60: txtLog
61: .setFormatter(new org.quickserver.util.logging.MicroFormatter());
62: logger.addHandler(txtLog);
63:
64: myServer.setAppLogger(logger); //imp
65:
66: //myServer.setConsoleLoggingToMicro();
67: myServer
68: .setConsoleLoggingFormatter("org.quickserver.util.logging.SimpleTextFormatter");
69: myServer.setConsoleLoggingLevel(Level.INFO);
70: } catch (Exception e) {
71: System.err.println("Could not create xmlLog FileHandler : "
72: + e);
73: }
74: //end of logger code
75:
76: try {
77: myServer.startServer();
78:
79: myServer.getQSAdminServer().setShellEnable(true);
80: myServer.startQSAdminServer();
81: } catch (AppException e) {
82: System.out.println("Error in server : " + e);
83: e.printStackTrace();
84: }
85: }
86:
87: public static float getQuickServerVersion() {
88: return QuickServer.getVersionNo();
89: }
90: }
|