Thread: online game
View Single Post
Old Apr 20th, 2008, 7:06 AM   #17
BinarySurfer
Programmer
 
BinarySurfer's Avatar
 
Join Date: Dec 2006
Posts: 50
Rep Power: 2 BinarySurfer is on a distinguished road
Re: online game

The server and client are connected and chatting?
Quote:
Originally Posted by cwl157 View Post
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
Well, that method is where the server accepts incoming data. Yeah, test is a lousy name now that I think of it.
For sending data, for both the client and the server, why don't you use the send method? When ever you want to send data from either, you just call the method with the info as an argument.
java Syntax (Toggle Plain Text)
  1. public Client c
  2.  
  3. c = new Client();
  4. c.connect();
  5. c.streams().
  6. c.processConnection();
  7. ... a lot of code later ...
  8. c.sendData("5, 8");
You can put the sendData call in the same method that gets the input from the user, so the data is sent to the server and send back and to the other client.
BinarySurfer is offline   Reply With Quote