Subversion Repositories programming

Rev

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

Rev Author Line No. Line
221 ira 1
/*******************************************************************************
2
 * File: P3_Client.java
3
 * Author: Ira W. Snyder (devel@irasnyder.com)
4
 * License: GNU General Public License v2
5
 * Class: CS380 - Computer Networking
6
 *
7
 * Assignment: Project #3
8
 * Date Last Modified: 2006-02-15
9
 *
10
 * Purpose: //FIXME
11
 ******************************************************************************/
12
 
223 ira 13
import java.net.*;
14
import java.io.*;
15
 
16
public class P3_Client
17
{
18
    private static IPAddr ip;
19
    private static String hw;
20
 
21
    private static final String hostName = "localhost";
22
    private static final int portNumber = 1337;
23
 
24
    public static void main (String[] args) throws Exception
25
    {
26
        Socket socket = null;
27
        PrintWriter out = null;
28
        BufferedReader in = null;
29
        BufferedReader kbd = null;
30
        String s = new String();
31
        boolean running = true;
32
 
33
        try
34
        {
35
            socket = new Socket (hostName, portNumber);
36
            out = new PrintWriter (socket.getOutputStream(), true);
37
            in = new BufferedReader (new InputStreamReader (
38
                                         socket.getInputStream()));
39
            kbd = new BufferedReader (new InputStreamReader (System.in));
40
        }
41
        catch (UnknownHostException e)
42
        {
43
            System.err.printf ("Can't resolve hostname: %s\n", hostName);
44
            System.exit (1);
45
        }
46
        catch (IOException e)
47
        {
48
            System.err.printf ("Couldn't get I/O for the connection to: %s\n", hostName);
49
            System.exit (2);
50
        }
51
 
52
        System.out.print ("Please type your Hardware Address: ");
53
        hw = kbd.readLine();
54
 
55
        // Send Hardware Address
56
        out.printf ("req IP %s\n", hw);
57
 
58
        while (running)
59
        {
60
            s = in.readLine();
61
            System.out.println (s);
62
 
63
            if (s.equals("IP Lease Time Expired"))
64
                running = false;
65
        }
66
 
67
        System.out.println ("Exiting");
68
 
69
        out.close();
70
        in.close();
71
        socket.close();
72
    }
73
}
74
 
75
 
76