KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dateserver > DateServer


1 /*
2  * This file is part of the QuickServer library
3  * Copyright (C) 2003-2005 QuickServer.org
4  *
5  * Use, modification, copying and distribution of this software is subject to
6  * the terms and conditions of the GNU Lesser General Public License.
7  * You should have received a copy of the GNU LGP License along with this
8  * library; if not, you can download a copy from <http://www.quickserver.org/>.
9  *
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 JavaDoc VER = "1.0";
28     public static void main(String JavaDoc s[]) {
29         String JavaDoc cmdHandle = "dateserver.CommandHandler";
30         String JavaDoc objHandle = "dateserver.ObjectHandler";
31         String JavaDoc auth = null;
32
33         QuickServer myServer = new QuickServer(cmdHandle);
34         myServer.setClientAuthenticationHandler(auth);
35         myServer.setPort(125);
36         myServer.setName("Date Server v " + VER);
37         if(getQuickServerVersion() >= 1.2) {
38             System.out.println("Using 1.2 feature");
39             myServer.setClientObjectHandler(objHandle);
40
41             //reduce info to Console
42
myServer.setConsoleLoggingToMicro();
43         }
44
45         //setup logger to log to file
46
Logger logger = null;
47         FileHandler txtLog = null;
48         File log = new File("./log/");
49         if(!log.canRead())
50             log.mkdir();
51         try {
52             logger = Logger.getLogger("");
53             logger.setLevel(Level.FINEST);
54
55             logger = Logger.getLogger("dateserver");
56             logger.setLevel(Level.FINEST);
57             txtLog = new FileHandler("log/DateServer.txt");
58             //reduce info
59
txtLog.setFormatter(new org.quickserver.util.logging.MicroFormatter());
60             logger.addHandler(txtLog);
61
62             myServer.setAppLogger(logger); //imp
63

64             //myServer.setConsoleLoggingToMicro();
65
myServer.setConsoleLoggingFormatter(
66                 "org.quickserver.util.logging.SimpleTextFormatter");
67             myServer.setConsoleLoggingLevel(Level.INFO);
68         } catch(Exception JavaDoc e){
69             System.err.println("Could not create xmlLog FileHandler : "+e);
70         }
71         //end of logger code
72

73         try {
74             myServer.startServer();
75
76             myServer.getQSAdminServer().setShellEnable(true);
77             myServer.startQSAdminServer();
78         } catch(AppException e){
79             System.out.println("Error in server : "+e);
80             e.printStackTrace();
81         }
82     }
83
84     public static float getQuickServerVersion() {
85         return QuickServer.getVersionNo();
86     }
87 }
88
89
90
Popular Tags