Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

client and server network

 
Olliver Lim Kam Sian
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everyone!! i have a client and server source code!
And i have to to implement a guess number game so that when the client connects he needs to play the game! here is the server and client code!
I've already implemented the game method called playGame in the server source code but can't get it to work. can any one help me to get the game working?





connection between server and client is successful!
thanks
olliver


Edit by mw: Added Code Tags for formatting.

[ October 05, 2007: Message edited by: marc weber ]

[ October 07, 2007: Message edited by: Olliver Lim Kam Sian ]

Edit by mw: Added opening code tag to Olliver's new code.
[ October 07, 2007: Message edited by: marc weber ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, please use Code Tags to keep your code's formatting intact. I've edited your post to add these.

Second, you've posted 488 lines of code. You gave us a hint where the problem might be (somewhere in the playGame method, lines 117 through 154), but that's not much to go on. Can you describe the problem a little better? Are you getting error messages? What exactly is it doing or not doing that you want to change?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've isolated your playGame method in this test code, and it seems to be working fine.

So now I really have to ask: What is the problem? (You mentioned that "connection between server and client is successful.")
[ October 05, 2007: Message edited by: marc weber ]
 
Olliver Lim Kam Sian
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

Thanks for considering my problem,I don't have problem concerning my connection, but to get the game to work when the connection happens.What i would like it to do is that when the client connects, the server ask the client to play the game, and the client actually can enter numbers and try to guess. for the time being the code compiles and connection is succesful but the game is not.

Thanks for helping!!
olliver
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tip: How to Ask Questions on JavaRanch - Isolate the Problem.

Notice how I isolated (what I thought was) your problem method in my code above. Is there a way you can do this to isolate your real problem here? That would help you in tracking it down, and it would help us to help you.
[ October 07, 2007: Message edited by: marc weber ]
 
Olliver Lim Kam Sian
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again!
Sorry I'm kinda new to the ranch so I don't exactly how to display my problems ok i'll try once more!!
ok this is the guessing random number code and i'm trying to implement it in the server code that I posted before!I know that the random number works, but it works in the console. I would like it to work from the client window when the connection is succesful.That's why i've given the whole code for client and server for you to have an idea where to put it.(sorry I know its long).Hope i'm getting better to posting problem and that this helps a bit more!

private void playGame() {
final BufferedReader In = new BufferedReader(new InputStreamReader(
System.in));

final int No = (int) (Math.random() * 9) + 51;
int GuessCount = 0;
int Guess;

displayMessage("A random number between 50 and 60 ");

do {
while (true) {
try {
displayMessage("Guess the number: ");
Guess = Integer.parseInt(In.readLine());
if (Guess > 50 && Guess < 60)
break;
} catch (NumberFormatException e) {
displayMessage("That's not a number. Try again.");
}
catch (IOException ioe) {
displayMessage("That's not a number. Try again.");
}

}

if (Guess < No)
displayMessage(Guess + "Number is too small.");
else if (Guess > No)
displayMessage(Guess + "Number is too big.");

GuessCount++;

} while (Guess != No);

displayMessage("You got it! The number was " + No
+ ". You guessed it in " + GuessCount + " attempts.");
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic