Page 1 of 1

Room Variable Update issue . . .

Posted: 08 Nov 2011, 20:46
by Fishypants
Hey everyone. I have everything working correctly, my question is more of a design question of the server.

This is what the docs say about when room variables update:
The event is fired when room variables are updated in a certain room. A client receives these notifications only from the room(s) where he's currently logged in.
To optimize bandwidth only the variables that changed are transmitted.

But this seems to be a waste and doesn't really optimize the bandwidth at all . . . In what situation would you really need to know that a variable changed, yet not want the value that the variable was set to? The current method seems like a lot of unnecessary work. So the logic is as follows:

1) Something happens on server and variables change. Server sends notification to all the clients in the room of this change.
2) All the clients need the value of the changed variable so they all ask the server for the value.
3) Server returns the value to all the clients.

This doesn't seem optimized at all. It's almost double the amount of work. Why can't the server send the variables that changed as well as their value? Like this:

1) Something happens on server and variables change. Server sends variables and values to clients.
2) Clients get new values.

Or am i missing something entirely? Just something that's been bothering me recently. It seems like there would be a speed increase (or maybe I'm completely wrong) with sending an initial heavier packet as opposed to a roundabout trip from server to client.

Posted: 08 Nov 2011, 20:50
by Fishypants
Hmmm upon further thinking, I suppose if there was data that you only wanted a select group of people to receive, then the current implementation would be ideal, since theres less data going to people who don't need it.

But unfortunately, this is not my case. Every variable in the room is a variable that everyone should know about and update to. In my case this seems more inefficient. Is there a way to force the server to send the values as well? Some awesome undocumented method thats not in the docs?

Posted: 08 Nov 2011, 22:15
by rjgtav
Hi. It seems there is some confusion about how the server handles the room variables. When you update some variables of a room, the server only sends to the users that are inside the name of the variable that was updated plus its value.

Despite the onRoomListUpdate method only having the room and the changedVars array, when that event is fired the client has also received the new values of those vars. So in that event you just do the room.getVariable("varName"). Note: this method doesnt send a request to the server asking for the new value, it only returns the value that is already stored on the client.

So as you can see, this is already improved a lot :-)

Posted: 09 Nov 2011, 02:44
by Fishypants
Wait, really? How have I missed that? I thought room.getVariable() requested the variables from the server . . . IF not then that's excellent news! :D I need to read up more on that. Do you happen to know where in the documentation it mentions the variables being stored in the client?

Posted: 09 Nov 2011, 02:52
by Fishypants
The Room class is used internally by the SmartFoxClient object to store the properties of each room.

:shock: Well so it does. Bah, I don't know how I overlooked that. Thanks for the insight rjgtav. I wish the documentation was a little more clearer on this subject, or maybe there is information somewhere else that I am blatantly overlooking. Anyways, thanks again! :D