Skip to content
Snippets Groups Projects
Commit 2e5c98ac authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

Gracefully handles dropped connections.

Closes #3
parent 96f699a0
No related branches found
No related tags found
No related merge requests found
......@@ -178,12 +178,23 @@ public class Chat {
boolean myTurnToTalk = isHost;
try {
while (!message.equals("EXIT")) {
try {
if (myTurnToTalk) {
message = localInput.readLine();
remoteOutput.println(encipher(message));
} else {
message = decipher(remoteInput.readLine());
String encipheredMessage = remoteInput.readLine();
if (encipheredMessage != null) {
message = decipher(encipheredMessage);
localOutput.println(message);
} else {
localOutput.println("Received null message: lost connection to remote chatter. Terminating.");
message = "EXIT";
}
}
} catch (SocketException ignored) {
localOutput.println("Unable to exchange message: lost connection to remote chatter. Terminating.");
message = "EXIT";
}
myTurnToTalk = !myTurnToTalk;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment