Worker.java (1136B)
1 package shlist; 2 3 import java.io.BufferedReader; 4 import java.io.IOException; 5 import java.io.InputStream; 6 import java.io.InputStreamReader; 7 import java.net.Socket; 8 9 public class Worker implements Runnable { 10 private Socket sock; 11 12 public Worker(Socket s) { 13 this.sock = s; 14 } 15 16 public void run() { 17 InputStream inp = null; 18 BufferedReader brinp = null; 19 try { 20 inp = sock.getInputStream(); 21 brinp = new BufferedReader(new InputStreamReader(inp)); 22 } catch (IOException e) { 23 return; 24 } 25 System.out.println("Started new thread"); 26 String line; 27 try { 28 line = brinp.readLine(); 29 if (line != null) { 30 System.out.println(line); 31 } 32 sock.close(); 33 brinp.close(); 34 System.out.println("Closing Socket"); 35 } catch (IOException e) { 36 try { 37 sock.close(); 38 brinp.close(); 39 System.out.println("Closing Socket"); 40 } catch (IOException e1) { 41 e1.printStackTrace(); 42 } 43 } 44 System.out.println("Exiting Thread"); 45 } 46 }