private void handleClient() { try { this.in = new BufferedReader(new InputStreamReader(client.getInputStream())); this.out = new PrintWriter(new OutputStreamWriter(client.getOutputStream())); if (authenticateClient()) { handleRequest(); } out.flush(); out.close(); in.close(); } catch (Exception ex) { Log.warn(Thread.currentThread().getName() + ": failure handling client request.", ex); } finally { closeClientSocket(); } }
private void closeClientSocket() { try { client.close(); } catch (IOException ex) { Log.warn(Thread.currentThread().getName() + ": failed to close client socket.", ex); } }
public void run() { System.out.println("starting " + threadname + " run method on port " + SudokuServer.PORT); System.out.flush(); try { Socket sock = new Socket(hostname, SudokuServer.PORT); PrintWriter dos = new PrintWriter(sock.getOutputStream()); BufferedReader dis = new BufferedReader(new InputStreamReader(sock.getInputStream())); dos.println(testcase); dos.flush(); String response = dis.readLine(); System.out.println( "Client " + threadname + " sent: " + testcase + " received response:" + response); dos.close(); dis.close(); synchronized (sc) { sc.result = response; } } catch (Exception e) { e.printStackTrace(); } System.out.println("finishing " + threadname + " run method"); }