@@ -0,0 +1,2403 @@
+package discoveryServer;%0A%0A/******************************************************************************%0A *%0A *  CS 6421 - Discovery Server%0A *  Compilation:  javac PrintServer.java%0A *  Execution:    java PrintServer %0A *  Team Member:  Yuan Gao, Bei Xia%0A *  Default Port: 9993%0A ******************************************************************************/%0A%0Aimport java.net.Socket;%0Aimport java.net.ServerSocket;%0Aimport java.io.IOException;%0Aimport java.io.PrintWriter;%0Aimport java.net.UnknownHostException;%0Aimport java.io.BufferedReader;%0Aimport java.io.InputStreamReader;%0A%0Apublic class PrintServer %7B%0A%0A%09public static void process(Socket clientSocket) throws IOException %7B%0A%09%09// open up IO streams%0A%09%09BufferedReader in = new BufferedReader(new InputStreamReader(%0A%09%09%09%09clientSocket.getInputStream()));%0A%09%09PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);%0A%0A%09%09/* Write a welcome message to the client */%0A%09%09out.println(%22**************************************************************************%22);%0A%09%09out.println(%22Welcome to the Print server!%22);%0A%09%09out.println(%22**************************************************************************%22);%0A%09%09/* read and print the client's request */%0A%09%09// readLine() blocks until the server receives a new line from client%0A%09%09String userInput;%0A%09%09if ((userInput = in.readLine()) == null) %7B%0A%09%09%09System.out.println(%22Error reading message%22);%0A%09%09%09out.close();%0A%09%09%09in.close();%0A%09%09%09clientSocket.close();%0A%09%09%7D%0A%09%09System.out.println(%22Received message: %22 + userInput);%0A%09%09// --TODO: lookup function;%0A%09%09out.println(userInput);%0A%0A%09%09// close IO streams, then socket%0A%09%09out.close();%0A%09%09in.close();%0A%09%09clientSocket.close();%0A%09%7D%0A%0A%09public static void main(String%5B%5D args) throws Exception %7B%0A%0A%09%09// check if argument length is invalid%0A%09%09// if(args.length != 1) %7B%0A%09%09// System.err.println(%22Usage: java ConvServer port%22);%0A%09%09// %7D%0A%09%09// create socket%0A%09%09// int port = Integer.parseInt(args%5B0%5D);%0A%09%09int port = 9993;%0A%09%09ServerSocket serverSocket = new ServerSocket(port);%0A%09%09System.err.println(%22Started server on port %22 + port);%0A%0A%09%09// wait for connections, and process%0A%09%09try %7B%0A%09%09%09while (true) %7B%0A%09%09%09%09// a %22blocking%22 call which waits until a connection is requested%0A%09%09%09%09Socket clientSocket = serverSocket.accept();%0A%09%09%09%09System.err.println(%22%5CnAccepted connection from client%22);%0A%09%09%09%09process(clientSocket);%0A%09%09%09%7D%0A%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09System.err.println(%22Connection Error%22);%0A%09%09%7D%0A%09%09System.exit(0);%0A%09%7D%0A%7D%0A

Create PrintServer.java