Sorry for the mouthful of a title!
Basically, I’m writing some code at the moment and it includes a chatroom. I’m wondering how best to handle people joining and leaving.
I’m doing this in HTML and Javascript and wondering whether it is ‘better’ to, when someone leaves or joins, to send the entire updated list of people to everyone else, or to only send the names of the person joining or leaving.
Basically, let’s say someone leaves a chat room of 10 people. (The rooms will usually have 10 or less people). Is it more wise for the server to send the updated list of 9 people to all other clients and just remove every item from the listbox and repopulate it, or should a message just be sent to everyone saying “this person joined/left” and then every client can update their listbox of users accordingly.
As far as I know, in Javascript, you can’t just go to an item in a listbox and remove it. You have to loop through the entire listbox and upon finding the desired item, remove it. This being the case, I imagine in my situation it may be better to send the entire updated list because there usually won’t be any more than 10 people in a room and it’s safer and users can’t get desynched from one another through strange connectivity issues. Is this indeed the case?
This decision is completely implementation-dependent.
From a basic point of view, sending a full list is more bullet-proof in order to keep the list’s consistency, as well as easier to maintain and implement.
Sending only the changes to the client’s browser will provide less bandwidth usage on both ends and suffice if well implemented.
However, if the bandwidth isn’t an issue and your project is a small-medium scope one, I’d go with the first option which is much easier to implement and maintain – unless you’re looking for a challenge or making an application for a huge number of users, then go for the second option.
Ultimately, the decision relies on the programmer’s conscience.
edit: As this doesn’t relate directly to code, maybe this question be more suitable for Programmers?