Thread: online game
View Single Post
Old Apr 19th, 2008, 4:59 PM   #16
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 323
Rep Power: 4 cwl157 is on a distinguished road
Re: online game

I am really confused. It does print out to all the clients a string that i enter on the server. Now how do i make it so the client can send Strings to the server and then the Server print them on all clients? I think that is the next step. That way in my game I can have the person enter their move via keyboard input and then pass it to the server which would then print it out on all clients so both clients could see all the moves. Then when there is a winner I could send that to all clients and have it displayed as well. So basically I need a method that takes a string and sends it to the server and then the server passes it to all clients which would be max 2 clients because 2 people play at once. Here is the Server class's receive method that I have been working on but does not work. I thought if this could return what is received as a String then that String could be passed into the send method and sent to all the clients. I just hangs when receive is hit.

java Syntax (Toggle Plain Text)
  1. private static String receive() throws IOException
  2. {
  3. String test = "";
  4. try
  5. {
  6. test = (String)input.readObject();
  7. System.out.print("\n" + test);
  8. } // end try
  9. catch(ClassNotFoundException classNotFoundException)
  10. {
  11. System.out.print("\nUnknown object recieved");
  12. } // end catch
  13. return test;
  14. } // end receive

Last edited by cwl157; Apr 19th, 2008 at 5:28 PM.
cwl157 is offline   Reply With Quote