Advertisement
chrisversloot

Berichten lezen in een bestaande socketverbinding

Feb 1st, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. /**
  2.      * Lees de berichten in de socket.
  3.      */
  4.     public void run() {
  5.         while(true) {
  6.             try {
  7.                 /* Bepaal of er nog een verbinding is */
  8.                 if(in == null) {
  9.                     try {
  10.                         mui.addMessage("<Verbinding is verbroken>");
  11.                         mui.exceptionEnable(LOCE_CONNECT_ERROR);
  12.                         this.shutdown();
  13.                     }
  14.                     catch(Exception e) {}
  15.                 }
  16.                
  17.                 /* Wacht tot er een nieuw bericht is */
  18.                 if(in.ready()) {
  19.                    
  20.                     /* Lees het bericht en stuur het naar de command handler */
  21.                     String command = in.readLine();
  22.                     handleCommands(command);
  23.                 }
  24.             } catch(NullPointerException e) {
  25.                
  26.             } catch (IOException e) {
  27.                 /* Vang een IOException af */
  28.                 e.printStackTrace();
  29.             }
  30.            
  31.         }
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement