|
@ -10,17 +10,19 @@ import java.net.Socket; |
|
|
|
|
|
|
|
|
public class ChatClient { |
|
|
public class ChatClient { |
|
|
|
|
|
|
|
|
private final int id; |
|
|
|
|
|
|
|
|
final int id; |
|
|
private final Socket s; |
|
|
private final Socket s; |
|
|
private final DataInputStream inputStream; |
|
|
private final DataInputStream inputStream; |
|
|
private final DataOutputStream outputStream; |
|
|
private final DataOutputStream outputStream; |
|
|
private final Thread t; |
|
|
private final Thread t; |
|
|
|
|
|
private final ChatServer server; |
|
|
|
|
|
|
|
|
public ChatClient(int id, Socket s, DataInputStream inputStream, DataOutputStream outputStream) { |
|
|
|
|
|
|
|
|
public ChatClient(int id, Socket s, DataInputStream inputStream, DataOutputStream outputStream, ChatServer server) { |
|
|
this.id = id; |
|
|
this.id = id; |
|
|
this.s = s; |
|
|
this.s = s; |
|
|
this.inputStream = inputStream; |
|
|
this.inputStream = inputStream; |
|
|
this.outputStream = outputStream; |
|
|
this.outputStream = outputStream; |
|
|
|
|
|
this.server = server; |
|
|
t = new Thread(() -> { |
|
|
t = new Thread(() -> { |
|
|
try { |
|
|
try { |
|
|
while (true) { |
|
|
while (true) { |
|
@ -34,6 +36,7 @@ public class ChatClient { |
|
|
} catch (IOException e) { |
|
|
} catch (IOException e) { |
|
|
Main.console.error("An error occurred while reading from client (" + s.getRemoteSocketAddress().toString() + ") [id: " + id + "]"); |
|
|
Main.console.error("An error occurred while reading from client (" + s.getRemoteSocketAddress().toString() + ") [id: " + id + "]"); |
|
|
e.printStackTrace(); |
|
|
e.printStackTrace(); |
|
|
|
|
|
server.disconnect(this); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
try { |
|
|
try { |
|
|