Client/Server Interaction Question

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

Post Reply
jimg
Posts: 7
Joined: 08 Sep 2010, 19:38

Client/Server Interaction Question

Post by jimg »

Can someone suggest the best approach for coordinating data between the client and server that relates to the user. If I'm understanding the documentation properly, it would seem that user variables are more appropriate for broadcasting information between users in a room - not synchronizing the state of a user between the client and server.

For example,

1. When the user logs in - what's the best way to return profile information from the server back to the client (such as Avatar details) - setUserVariables or include it in a sendResponse?

2. When the user changes the avatar on the client-side, what's the best mechanism to send the changes to the server AND do you wait for the server to confirm the changes before applying them on the client.

Any advice on general approach is greatly appreciated.

Thanks!
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

This is what I do:

1. After a client logged in, I send everything to that client including avatars, gold etc using sendResponse method. On the server, I also store the avatar info as a user variable (but a shorter version). So when other users join the same room, they'll get the user variables straight away.

2. I just update the user variable when the avatar changes without boardcasting the event (in server side - as I would need to validate the data). All users in the current room won't know yet, until they re-join the room. I don't find it important to update the user's avatar in real time.
Smartfox's forum is my daily newspaper.
jimg
Posts: 7
Joined: 08 Sep 2010, 19:38

Post by jimg »

Thanks for the timely response!

That gives me some great information to work with.
Post Reply