I've a problem with Server/Client socket. The server sends several object to the client, but the client always has the first message that receive and doesn't receive the other. If I print a message in the client, it receive message, but if I print these message they are always the same. But if I print the message on server side the message are different. Can you help me? I've seen that if I send Integer all works fine. There is the problem only with the object that I must send. This is the code of the server and the client(they are linked to a GUI and a controller):
Server
@Override
public void update(Observable o, Object arg) {
if(o instanceof ModelChanges){
arrayPlayersSocket = socketServerCreate.getArrayPlayerSocket();
Iterator<ObjectOutputStream> arrayIterator = arrayPlayersSocket.iterator();
while(arrayIterator.hasNext()){
outputMessage = (ObjectOutputStream)arrayIterator.next();
System.out.println(((ModelChanges)arg).getAzione());
try {
outputMessage.writeObject(arg);
outputMessage.flush();
/*if(arrayPlayersSocket.indexOf(outputMessage) != controller.getTurn().getCurrentPlayer()){
ModelChanges modelChanges = new ModelChanges();
modelChanges.spegniBottoniOnLine(false, false, false);
outputMessage.writeObject(modelChanges);
outputMessage.flush();
}*/
} catch (IOException e) {
System.out.println("IOException while the server sends an object to the client!");
return;
}
}
}
}
Client
@Override
public void run() {
while(true){
try {
message = inputMessage.readObject();
if(message instanceof Integer){
socketClientCreate.setArrayIndex((Integer)message);
}else if(message instanceof ModelChanges){
ModelChanges modelChanges = (ModelChanges)message;
view.getMappa().repaintView(modelChanges);
}
} catch (ClassNotFoundException e) {
System.out.println("ClassNotFoundException waiting a message from the server!\n"+e.getStackTrace());
return;
} catch (IOException e) {
}
}
}