Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2018
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. static class ClientHandler implements Runnable {
  2.         Scanner scn = new Scanner(System.in);
  3.         public String name;
  4.         final DataInputStream dis;
  5.         final DataOutputStream dos;
  6.         Socket s;
  7.         boolean isloggedin;
  8.  
  9.         // constructor
  10.         public ClientHandler(Socket s, String name, DataInputStream dis, DataOutputStream dos) {
  11.             this.dis = dis;
  12.             this.dos = dos;
  13.             this.name = name;
  14.             this.s = s;
  15.             this.isloggedin = true;
  16.         }
  17.  
  18.         @Override
  19.         public void run() {
  20.             received = "";
  21.             while (true) {
  22.                 try {
  23.                     while (!received.equals("exit")) {
  24.                         received = dis.readUTF();
  25.                         textArea.append(name + ":\n" + received + "\n");
  26.                     }
  27.                     if (received.equals("exit")) {
  28.                         this.isloggedin = false;
  29.                         this.s.close();
  30.                         break;
  31.                     }
  32.                 } catch (IOException e) {
  33.                     // e.printStackTrace();
  34.                 }
  35.             }
  36.             try {
  37.                 this.dis.close();
  38.                 this.dos.close();
  39.             } catch (IOException e) {
  40.                 // e.printStackTrace();
  41.             }
  42.         }
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement