Subversion Repositories programming

Rev

Rev 221 | Rev 224 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*******************************************************************************
 * File: P3_Client.java
 * Author: Ira W. Snyder (devel@irasnyder.com)
 * License: GNU General Public License v2
 * Class: CS380 - Computer Networking
 *
 * Assignment: Project #3
 * Date Last Modified: 2006-02-15
 *
 * Purpose: //FIXME
 ******************************************************************************/

import java.net.*;
import java.io.*;

public class P3_Client
{
    private static IPAddr ip;
    private static String hw;

    private static final String hostName = "localhost";
    private static final int portNumber = 1337;

    public static void main (String[] args) throws Exception
    {
        Socket socket = null;
        PrintWriter out = null;
        BufferedReader in = null;
        BufferedReader kbd = null;
        String s = new String();
        boolean running = true;

        try
        {
            socket = new Socket (hostName, portNumber);
            out = new PrintWriter (socket.getOutputStream(), true);
            in = new BufferedReader (new InputStreamReader (
                                         socket.getInputStream()));
            kbd = new BufferedReader (new InputStreamReader (System.in));
        }
        catch (UnknownHostException e)
        {
            System.err.printf ("Can't resolve hostname: %s\n", hostName);
            System.exit (1);
        }
        catch (IOException e)
        {
            System.err.printf ("Couldn't get I/O for the connection to: %s\n", hostName);
            System.exit (2);
        }

        System.out.print ("Please type your Hardware Address: ");
        hw = kbd.readLine();

        // Send Hardware Address
        out.printf ("req IP %s\n", hw);

        while (running)
        {
            s = in.readLine();
            System.out.println (s);

            if (s.equals("IP Lease Time Expired"))
                running = false;
        }

        System.out.println ("Exiting");

        out.close();
        in.close();
        socket.close();
    }
}