|
1 | 1 | package networking; |
2 | | -import java.io.BufferedInputStream; |
3 | | -import java.io.BufferedOutputStream; |
| 2 | + |
4 | 3 | import java.io.DataInputStream; |
5 | 4 | import java.io.DataOutputStream; |
| 5 | +import java.io.EOFException; |
6 | 6 | import java.io.IOException; |
7 | 7 | import java.net.Socket; |
| 8 | +import java.net.SocketException; |
8 | 9 | import java.util.concurrent.ExecutorService; |
9 | 10 |
|
10 | 11 | public class Client implements Runnable { |
@@ -72,7 +73,11 @@ public void run() { |
72 | 73 | try { |
73 | 74 | // TODO: Just keeping track of a number for now |
74 | 75 | synchronized (this.input) { |
75 | | - this.threadPool.execute(new ClientRead(this.input.readInt(), this.trackClient)); |
| 76 | + try { |
| 77 | + this.threadPool.execute(new ClientRead(this.input.readInt(), this.trackClient)); |
| 78 | + } catch (EOFException | SocketException e) { |
| 79 | + // Ignore, client has just disconnected |
| 80 | + } |
76 | 81 | } |
77 | 82 | } catch (IOException e) { |
78 | 83 | System.out.print("Error reading from socket: " + this.socket.toString() + ": " + e.toString()); |
@@ -132,6 +137,8 @@ public void run() { |
132 | 137 | synchronized (this.getClient().output) { |
133 | 138 | try { |
134 | 139 | this.getClient().output.writeInt(this.data); |
| 140 | + } catch (SocketException e) { |
| 141 | + // Ignore client has just disconnected |
135 | 142 | } catch (IOException e) { |
136 | 143 | System.out.println("Error writing to socket: " + this.getClient().socket.toString()); |
137 | 144 | e.printStackTrace(); |
|
0 commit comments