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

Client user is re-prompted if address is not exactly four octets.

Closes #7
parent 84956cdc
Branches
No related tags found
No related merge requests found
......@@ -89,15 +89,21 @@ public class Chat {
try {
String addressString = scanner.nextLine();
String[] tokens = addressString.split("\\.");
if (tokens.length == 4) {
for (int i = 0; i < 4; i++) {
address[i] = Byte.parseByte(tokens[i]);
}
} else {
System.out.println("The IP address should be four dot-separated numbers; <"
+ addressString + "> does not conform.");
haveGoodAddress = false;
}
} catch (NumberFormatException nfException) {
System.out.println("The IP address should be exactly as reported to the host user.");
String message = nfException.getMessage();
if (message.startsWith("Value out of range. Value")) {
String[] messageTokens = message.split("\"");
long value = Long.parseLong(messageTokens[1]); // this is fragile to an unexpected message format
long value = Long.parseLong(messageTokens[1]); // this may break if message format changes
if ((127 < value) && (value < 256)) {
System.out.println("Note that Java does not have unsigned integers, so subtract 256 from " +
"values greater than 127. For example, " + value + " should be " + (value - 256) + ".");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment