Sending an object via sockets - all fields but array updating
I have a client/server multiplayer game application for my final year project at uni.
The clients connect to the server and choose a game to join.
Whenever any client who is connected to that game makes a move, all the other clients need to be updated. The server will then send a GameState of the game to all the clients. The client receives the GameState object and handles it suitably.
The GameState object includes:
- int playerTurn
- String gameName
- Player players
and other relative fields.
The first time each client receives the GameState object works perfectly fine, everything is as it should be.
However any further GameState objects that are received do not work so well. All the normal fields variables areas they should be, changing if they need to be. Every single array that is in the GameState object reverts back to the same array that was received the first time round. Whether the array is of type Player/ int / string - it doesnt matter.
So the client receives the new GameState object with the appropriate values changed apart from all the arrays.
The server is sending the GameState object with the appropriate values (including the arrays). I had it print out the state that it sent and even write it to a file and in both cases the arrays were as they should be.
The client also reads in the object from the file several times and the arrays change as they should. The problem only occurs over sockets.
If I change for datatype, for example:
instead of int numbers being [10,20,30,40,50]
I have int1 = 10, int2 = 20, etc
then these values are sent and received correctly, its just when it exists in an array it defaults back to the values that were in the first object.
Is there something about sending arrays in sockets that I am missing?
alrprpvgjkvqypjsvqjyxvhxmrudrwrferxhello guys need advice
mmmkwtzbxwtgguonwell, hi admin adn people nice forum indeed. how's life? hope it's introduce branch ;)