File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes client and server network Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "client and server network" Watch "client and server network" New topic
Author

client and server network

Olliver Lim Kam Sian
Greenhorn

Joined: Sep 26, 2007
Posts: 12
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

Joined: Aug 31, 2004
Posts: 11343

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?


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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

Joined: Sep 26, 2007
Posts: 12
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

Joined: Aug 31, 2004
Posts: 11343

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

Joined: Sep 26, 2007
Posts: 12
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.");
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: client and server network