Let me start by saying I know this is a lot of code, and so please bear with me. I am working on a project, where I\'m porting Oracle\'s Knock-Knock client/server example into a
No need for new answers. Thanks to Paul above, for encouraging me to figure it out on own :
The issue was that, I overlooked the importance of FixedSequenceMessageProtocol
class
Since the Client is hard-coded to send everything in the large StateResponses
array, it needed to have a fourth field for "ack" (should ideally be a multidimensional array), which pairs with the Server's sending of "nowlogged" :
StateResponses[] = { "Permission granted." , "What is Alabama population", "y", "ack", //00
"Permission granted." , "What is Alaska population", "y", "ack",
After this, in the FixedSequenceMessageProtocol
class I added a new constant final variable, to indicate the pending-status after we log a state position, SENTPERMISSION2
:
private static final int WAITING = 0;
private static final int SENTPERMISSION = 1;
private static final int SENTPERMISSION2 = 2; // ** new line
private static final int SENTCLUE = 3;
private static final int ANOTHER = 4;
Following, I just need to add another case within the nested-if blocks in the FixedSequenceMessageProtocol
class:
/* etc more code */ {
if (theInput.equalsIgnoreCase(clues[currentPopulationRequest])) {
theOutput = answers[currentPopulationRequest] + " Want another? (y/n)";
currentPopulationRequest++;
state = SENTPERMISSION2 ; //sentpermssion2, & in sentPermission2 put another
} else {
theOutput = "You're supposed to say \"" +
clues[currentPopulationRequest] +
"! Try again. Request to send a state population";
state = SENTPERMISSION;
}
}
else if (state == SENTPERMISSION2) {
if (theInput.equalsIgnoreCase("y")) {
theOutput = "Status logged";
state = ANOTHER;
} else {
theOutput = "Bye.";
state = WAITING;
}
}
else if (state == ANOTHER) {
if (theInput.equalsIgnoreCase("ack")) { /* etc more code */