This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 18th, 2012  |  syntax: None  |  size: 1.60 KB  |  views: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public void run() {
  2.         ServerSocket server;
  3.         try {
  4.             server = new ServerSocket(PORT);
  5.         } catch (BindException ex) {
  6.             this.logger.log(Level.SEVERE, "Failed to start the server on port" + PORT, ex);
  7.             return;
  8.         } catch (IOException ex) {
  9.             this.logger.log(Level.SEVERE, "Failed to start the server on port" + PORT, ex);
  10.             return;
  11.         }
  12.         while (isAlive()) {
  13.             Socket skt;
  14.             try {
  15.                 skt = server.accept();
  16.             } catch (Exception ex) {
  17.                     this.logger.info("Error while waiting for connection");
  18.                     this.logger.info("Ignore this if you were disabling the plugin/server");
  19.                 return;
  20.             }
  21.             logger.info("Socket accepted.");
  22.  
  23.             BufferedReader reader;
  24.             try {
  25.                 skt.setKeepAlive(true);
  26.                 reader = new BufferedReader(new InputStreamReader(skt.getInputStream()));
  27.             } catch (Exception ex) {
  28.                 this.logger.log(Level.SEVERE, "Encountered an error while opening socket data connections.", ex);
  29.                 return;
  30.             }
  31.  
  32.             CommandHandler handler = new CommandHandler(bukkitServer, logger);
  33.             try {
  34.                 String line;
  35.                 while ((line = reader.readLine()) != null) {
  36.                     handler.parse(line);
  37.                 }
  38.             } catch (Exception ex) {
  39.                 this.logger.log(Level.SEVERE, "Encountered an error while reading from socket.", ex);
  40.             }
  41.         }
  42.     }
clone this paste RAW Paste Data