001package edu.pdx.cs410J.net;
002
003import java.io.*;
004import java.net.*;
005
006/**
007 * A client that connects to a {@link DateServer} and reads the {@link
008 * java.util.Date} sent to it as a <code>String</code>.  The important
009 * things to note are the ports that are used to communicate.
010 *
011 * @author David Whitlock
012 * @since Fall 2005
013 */
014public class DateClient {
015
016  private static final PrintStream out = System.out;
017  private static final PrintStream err = System.err;
018
019  /**
020   * Connects to a server and receives the date.
021   */
022  public static void main(String[] args) {
023    String host = args[0];
024    int port = Integer.parseInt(args[1]);
025
026    try {
027      out.println("Client connecting to " + host + ":" + port);
028      Socket socket = new Socket(host, port);
029
030      out.println("Client running on " + socket.getLocalAddress() +
031                  ":" + socket.getLocalPort());
032      out.println("Client communicating with " + socket.getInetAddress() 
033                  + ":" + socket.getPort());
034
035      InputStream is = socket.getInputStream();
036      InputStreamReader isr = new InputStreamReader(is);
037      BufferedReader br = new BufferedReader(isr);
038
039      out.println("Client read " + br.readLine());
040      out.close();
041
042    } catch (IOException ex) {
043      err.println("** IOException: " + ex);
044      System.exit(1);
045    }
046  }
047
048}