Guest User

UpdateServer

a guest
Sep 24th, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. public class UpdateServer {
  2.  
  3.     /**
  4.      * @param args
  5.      */
  6.     public static void main(String[] args) {
  7.         try{
  8.             System.out.println("Listening on port 7564....");
  9.            
  10.             ServerSocket sock = new ServerSocket(7564);
  11.             Socket connection = sock.accept();
  12.            
  13.             BufferedReader clientIn = new BufferedReader(
  14.                     new InputStreamReader(connection.getInputStream()));
  15.             DataOutputStream serverOut = new DataOutputStream(connection.getOutputStream());
  16.            
  17.             System.out.println("Connected to client!");
  18.             System.out.println("Waiting for the client to send name....");
  19.            
  20.             String client = clientIn.readLine();
  21.            
  22.             boolean reply = getReplyText(client);
  23.            
  24.             serverOut.writeBytes(Boolean.toString(reply));
  25.            
  26.             sock.close();
  27.             connection.close();
  28.             clientIn.close();
  29.             serverOut.close();
  30.            
  31.             main(null);
  32.         }
  33.         catch(IOException ex){
  34.            
  35.         }
  36.     }
  37.    
  38.     public static boolean getReplyText(String clientName){
  39.         if (clientName.equals("mmu")){
  40.             return true;
  41.         }
  42.         if (clientName.equals("ep")){
  43.             return false;
  44.         }
  45.         else {
  46.             System.out.println("This isn't a recognized client.");
  47.             return false;
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment