/** * Preprocesses the messages from the server * * @param message */ private synchronized void preprocessServerMessage(String message) { if (message == null) { this.stop(); try { reader.close(); writer.close(); } catch (IOException ioe) { ioe.printStackTrace(); } sendMessage(CLIENT, "Connection Closed by Server"); _group = ""; } else if (message.equals("") == false) processServerMessage(message); }
/** * Connect to the server * * @param host Serverhost * @param port Serverport */ private void connect(String host, int port) { if (_status == NOTCONNECTED) { try { socket = new Socket(host, port); } catch (Exception ex) { ex.printStackTrace(); } try { reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8")); writer = new PrintWriter(socket.getOutputStream(), true); _status = CONNECTED; } catch (IOException ex) { ex.printStackTrace(); } if (_status == CONNECTED) { thread = new Thread(this); thread.start(); } } }