Advertisement
Guest User

Untitled

a guest
Mar 12th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1. public void run(){
  2.         String inputLine;
  3.        
  4.         try
  5.         {
  6.             //input stream reader
  7.             //get socket writing and reading streams
  8.             BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
  9.             DataOutputStream out = new DataOutputStream(socket.getOutputStream());
  10.            
  11.             out.writeBytes(simpleprotocol.createMessage("sign-up", "true", "Welcome to my Server") + "\n");
  12.  
  13.             //Now start reading input from client
  14.             while((inputLine = in.readLine()) != null) {
  15.                 //reply with the same message, adding some text
  16.                 chooseFunction(inputLine);
  17.                 out.writeBytes((inputLine) +"\n");
  18.             }
  19.              
  20.             //client disconnected, so close socket
  21. //            socket.close();
  22.         }
  23.        
  24.         catch (IOException e)
  25.         {
  26.             System.out.println("IOException on socket : " + e);
  27.             e.printStackTrace();
  28.         }
  29.     }
  30.  
  31.    
  32.     public void chooseFunction(String message){
  33.         String[] received = simpleprotocol.decodeMessage(message);
  34.         String function = received[0];
  35.        
  36.         if(function.equals("sign-up")){
  37.             userSignUp(message);
  38.         }else if(function.equals("sign-in")){
  39.             userSignIn(message);
  40.         }else if(function.equals("get-message")){
  41.             getMessage(message);
  42.         }else if(function.equals("send-message")){
  43.             sendMessage(message);
  44.         }
  45.     }
  46.    
  47.    
  48.     public void userSignUp(String credentials){
  49.         String[] received = simpleprotocol.decodeMessage(credentials);
  50.         String username = received[1];
  51.         String password = received[2];
  52.        
  53.        
  54.             if(!(userDetails.containsKey(username))){
  55.                 if(username.length() >=5 && username.length() <=20){
  56.                     if(password.length() >= 8 && password.length() <=32){
  57.                             userDetails.put(username, password);
  58.             simpleprotocol.createMessage("sign-up", "true","User successfully signed up");
  59.            
  60.                     }
  61.                 }
  62.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement