Rev 222 | Rev 224 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
import java.net.*;import java.io.*;public class P3_ServerThread extends Thread{private Socket socket = null;private DHCPTable table = null;public P3_ServerThread (Socket socket, DHCPTable table){super ("P3_ServerThread");this.socket = socket;this.table = table;}public void run (){try{PrintWriter out = new PrintWriter (socket.getOutputStream(), true);BufferedReader in = new BufferedReader (new InputStreamReader (socket.getInputStream()));String inputLine, outputLine;DHCPTableEntry e, expired;// Try to get REQ messageinputLine = in.readLine();String[] splitInput = inputLine.split(" ");if (splitInput.length != 3 &&!splitInput[0].equals("req") &&!splitInput[1].equals("IP")){System.err.println ("REQ was not the first message!");out.println ("BAD REQUEST");return; // Leave uncleanly}e = table.addEntry (splitInput[2]);// Print out DHCP Server infoSystem.out.printf ("Client Added: IP=%s -- HW=%s\n", e.getIPAddr(), e.getHWAddr());// Send out the client's IP Addressout.println ("IPAddr: " + e.getIPAddr());expired = table.timeoutEntry (e.getIPAddr());while (expired == null){expired = table.timeoutEntry (e.getIPAddr());// wait for timeout (accomplished above)}// Print DHCP Server infoSystem.out.printf ("Client Expired: IP=%s -- HW=%s\n",expired.getIPAddr(), expired.getHWAddr());// Tell the client that it expiredout.println ("IP Lease Time Expired");out.close();in.close();socket.close();}catch (IOException e){e.printStackTrace();}}}