-1

enter image description here

// CLIENT SOURCE

while(!isStop){
    try{
        Object ob = mc.getOis().readObject();
        try{ 
            message = (String) ob;
        } catch (ClassCastException e){

            try {
                user = (User) ob;
                mc.user = (User) ob;
                message = "none";
            } catch ( ClassCastException ee ) {

                Room room = (Room) ob;
                mc.setRoom(room);   
                System.out.println("room come in");
                for (int i = 0; i<mc.room.userlist.size(); i++ )
                {
                    System.out.println("ThreadUserNum:" + room.userlist.get(i).getPlayer_Num());
                }


                mc.roomidimg();
                message = "none";

            }   
        }
    }
}

// SERVER SOURCE
public void roombroodcast ( Room msg, int room_id) throws IOException{
    if (room_id == 1){
        for( ServerThread ct : sv.getroom1list() ){
            for( int i = 0; i<msg.getUserlist().size(); i++){
                System.out.println(i + "broodcast:" + msg.getUserlist().get(i).getUser_Id());
            }
            ct.send( msg );
        }
    } else {
        for( ServerThread ct : sv.getroom2list() ){
            ct.send( msg );
        }
    }
}

We are making a game but we have some problems. The first user, who entered the game first, cannot get the other user's room class broadcasting. I mean, the other user or another user can get the room class broadcasting but the first one cannot get the updated room information. How can I update the room class broadcasting problem? We are using sockets to communicate.

user207421
  • 305,947
  • 44
  • 307
  • 483
Park J
  • 3
  • 1

1 Answers1

0

You are always sending the same object, so serialization will not actually re-send it: it economizes, as described in the Object Serialization Specification. So updating it and sending it again will not affect the object received at the receiver.

You need to investigate ObjectOutputStream.reset() or ObjectOutputStream.writeUnshared().

user207421
  • 305,947
  • 44
  • 307
  • 483
  • 1
    oh..we solved it. our team is very happy because of you. you saved our project. – Park J Jul 22 '18 at 08:15
  • 1
    You may also like to accept the answer if it helped you! Please see how to accept an answer here -> https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work. – Am_I_Helpful Jul 22 '18 at 09:11
  • @ParkJ No. **I** solved it. You applied the solution I posted. If you found it useful you should upvote it and if it solved your problem you should at least consider accepting it. – user207421 Jul 22 '18 at 10:18