001: /*
002: * This file is part of the QuickServer library
003: * Copyright (C) 2003-2005 QuickServer.org
004: *
005: * Use, modification, copying and distribution of this software is subject to
006: * the terms and conditions of the GNU Lesser General Public License.
007: * You should have received a copy of the GNU LGP License along with this
008: * library; if not, you can download a copy from <http://www.quickserver.org/>.
009: *
010: * For questions, suggestions, bug-reports, enhancement-requests etc.
011: * visit http://www.quickserver.org
012: *
013: */
014:
015: package dateserver;
016:
017: import java.io.*;
018: import java.net.*;
019: import java.util.*;
020: import java.util.logging.*;
021:
022: public class DateServerClient {
023:
024: public static void main(String args[]) {
025: Logger logger = Logger.getLogger("");
026: logger.setLevel(Level.FINEST);
027: logger.getHandlers()[0].setLevel(Level.FINEST);
028: logger.getHandlers()[0]
029: .setFormatter(new org.quickserver.util.logging.SimpleTextFormatter());
030:
031: ObjectOutputStream oos = null;
032: ObjectInputStream ois = null;
033: BufferedReader br;
034: BufferedWriter bw;
035: PrintWriter pw;
036: Socket socket;
037: int port = 125;
038: Date date;
039: String send;
040: if (args.length < 2) {
041: System.err.println("Usage : "
042: + "\n DateServerClient ip_address port");
043: System.exit(0);
044: }
045: try {
046: port = Integer.parseInt(args[1]);
047: socket = new Socket(args[0], port);
048:
049: logger.info("Connected to server.");
050:
051: br = new BufferedReader(new InputStreamReader(socket
052: .getInputStream()));
053: bw = new BufferedWriter(new OutputStreamWriter(socket
054: .getOutputStream()));
055: pw = new PrintWriter(bw, true);
056:
057: logger.info("Got : " + br.readLine());
058:
059: send = "hi server";
060: pw.println(send);
061: logger.info("Got : " + br.readLine());
062:
063: //for(int i=0;i<20;i++) {
064:
065: send = "exchange date";
066: pw.println(send);
067:
068: logger.fine("Opening ObjectInputStream..");
069: ois = new ObjectInputStream(socket.getInputStream());
070: logger.fine("Reading.. object..");
071: date = (Date) ois.readObject();
072: logger.fine("Done");
073: logger.info("Got : Server Date : " + date);
074:
075: logger.fine("Opening getOutputStream..");
076: oos = new ObjectOutputStream(socket.getOutputStream());
077: date = new Date();
078: logger.fine("Writing.. object..");
079: oos.writeObject(date);
080: oos.flush();
081: logger.fine("Done");
082:
083: logger.fine("Writing.. string..");
084: send = "thanks for the date";
085: pw.println(send);
086: logger.fine("Reading.. String");
087: logger.info("Got : " + br.readLine());
088: //}
089: logger.fine("Writing.. string..");
090: send = "quit";
091: pw.println(send);
092: logger.fine("Reading.. String");
093: logger.info("Got : " + br.readLine());
094:
095: pw.close();
096: br.close();
097: bw.close();
098: oos.close();
099: ois.close();
100: } catch (Exception e) {
101: logger.warning("Error " + e);
102: }
103: }
104: }
|