•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 391,158 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,243 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 564 | Replies: 2 | Solved
![]() |
•
•
Join Date: May 2007
Posts: 8
Reputation:
Rep Power: 0
Solved Threads: 0
Now i created a Client for the HOPP. i made a button which submits the guess to the server, but logically this doesnt output. What do you think seems to be the problem here.
public void actionPerformed(ActionEvent e){
String command = e.getActionCommand();
if(command.equals("Join Game")){
serverResponseArea.append("Sending join game request\n");
try{
clientHOPP.send(new Message(JOIN_REQUEST));
Message msg = (Message)clientHOPP.receive();
if(msg.getType() == JOIN_ACK){
serverResponseArea.append("Successfully joined game\n");
activeGame = true;
joinButton.setEnabled(false);
}
} catch (IOException e1) {
serverResponseArea.append("Communication Error: "+e1.getMessage());
} catch (ClassNotFoundException cnf) {
serverResponseArea.append(cnf.getMessage());
}
}
else if(command.equals("Submit Guess")){
String inString = guessField.getText().trim();
if(inString == null || inString.length() == 0){
serverResponseArea.append("Please enter a number \n");
}
int input = Integer.parseInt(inString);
serverResponseArea.append("Guess is: " + inString +"\n");
try{
clientHOPP.send(new Message(input));
/*Test*/serverResponseArea.append(input+" sent.\n");
guessField.setText("");
Message inMsg = (Message)clientHOPP.receive();
if(inMsg.getType()== GUESS_RESPONSE)
{
GuessResponse response = (GuessResponse)inMsg.getMessageContents();
if(response.getResponseType()==HIGHER)
serverResponseArea.append("(Guess # "+response.getGuessNumber()+"): HIGHER!");
else if(response.getResponseType() == LOWER)
serverResponseArea.append("(Guess # "+response.getGuessNumber()+"): LOWER!");
else if(response.getResponseType() == INVALID_NUMBER)
serverResponseArea.append("Invalid number. Please choose a number between 1 - 999");
else if(response.getResponseType() == WIN)
serverResponseArea.append("Congratulations. You Win in "+response.getGuessNumber()+" guesses");
else if(response.getResponseType() == LOSE)
serverResponseArea.append("Sorry, you lose");
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch(ClassNotFoundException cnf){
serverResponseArea.append(cnf.getMessage());
}
serverResponseArea.append(inString+"\n");
guessField.setText("");
}
}
} This will not be very easy to debug with just the code you posted, as there are several interacting classes here. If you do not have an IDE that will let you step through the code as it executes, then you will need to place assertions or System.out.println() statements at the various stages to verify what is being received and processed on the client and server side. I would recommend starting with testing what response the client is receiving. If that result is not correct then check how the server is processing the input. Good luck!
If you are getting specific exceptions or odd behavior you don't understand, post them back here and perhaps we can help.
If you are getting specific exceptions or odd behavior you don't understand, post them back here and perhaps we can help.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
- Error in exception(RMI) (Java)
- Logic error? (C++)
- Erm, logic error?! (C++)
- Error/Exception handling help (Python)
- Exception in thread "main" java.lang.NoClassDefFoundError: Invaders Error (Java)
- Could someone please help me with this logic error?? (VB.NET)
- Program Compiles fine, but error upon Running (Java)
- TCPIP.sys **STOP** Error! HELP! (Windows NT / 2000 / XP / 2003)
Other Threads in the Java Forum
- Previous Thread: Dynamic Loading
- Next Thread: how to use switch statement in java on strings



Linear Mode