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 { ...@@ -178,12 +178,23 @@ public class Chat {
boolean myTurnToTalk = isHost; boolean myTurnToTalk = isHost;
try { try {
while (!message.equals("EXIT")) { while (!message.equals("EXIT")) {
try {
if (myTurnToTalk) { if (myTurnToTalk) {
message = localInput.readLine(); message = localInput.readLine();
remoteOutput.println(encipher(message)); remoteOutput.println(encipher(message));
} else { } else {
message = decipher(remoteInput.readLine()); String encipheredMessage = remoteInput.readLine();
if (encipheredMessage != null) {
message = decipher(encipheredMessage);
localOutput.println(message); 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; myTurnToTalk = !myTurnToTalk;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment