Jump to content


Object I/o Over Network


  • Please log in to reply
No replies to this topic

#1 Avero

Avero

    Advanced Member

  • Members
  • PipPipPip
  • 44 posts
  • Location:Earth

Posted 13 July 2010 - 12:15 AM

Hi all,

I am trying to make a chat program for fun and I'm having some troubles.  I use 2 sockets, one for messages and one for commands (kick, ban, display name, etc.)   The messages works perfectly, but the commands don't seem to work at all.  The client sends a command in the form of a "Command" object that has a String type and a String[] data.  The server must be able to handle multiple clients and so gives each new connected client a thread that preforms I/O going to/from that client.  The problem is that no commands are being received by the server.  The client can send all it wants, but the server seems to be unable to receive them.  The connection between the sockets is ok, well I don't get any Exceptions from connecting so I assume it's a problem with my usage of ObjectInputStream and ObjectOutputStream.

Here is the code sending a command from the client:
CODE

private static void sendCMD(Command command) {
try {
cmdOut.writeObject(command);
try {
sleep(5);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
cmdOut.flush();

} catch (IOException ex) {
ex.printStackTrace();
}

}

Here is the code attempting to get the command in the Server:
CODE

if(commandIn.available()>0){
parseCommand(commandIn.readObject());
}

Thanks in advance for your help!