I try to make a card game.I have a thread problem. I construct objectinputstream only once and then just send a reference to it to the other Thread and two thread try to read an object from same objectinputstream at the same time.The same problem is java.io.StreamCorruptedException: invalid type code: 00 but it didn't solved.
ClientService Thread:
while (true) {
try {
Message message = (Message) in.readObject();
handleClientMessage(message);
if (message.getType() == Message.messageType.ClientDisconnect) {
break;
}
} catch (IOException ex) {
Logger.getLogger(ClientServiceThread.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(ClientServiceThread.class.getName()).log(Level.SEVERE, null, ex);
}
}
Game Thread
public void run() {
startGame();
while (true) {
try {
Message msg = (Message) inPlayer1.readObject();
handlePlayerMessage(msg);
} catch (IOException ex) {
Logger.getLogger(Game.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(Game.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
in and inplayer1 the same objectinputstream.I get an exception : java.io.StreamCorruptedException: invalid type code: 00 .Two classes make a different job only this part is similar.Please give an advise how I solve this problem.Is there any way ?