That is a matter for your chat protocol. Usually the first thing the
client does after it connects is to identify itself, as soon as he
does it you can add it to the global users->sockets map. When he joins
a group you add it to that groups map, etc. After the user identifies
itself you can also keep a reverse sockets->users map, too, remember
that in Lua a table key can be anything, not just a string or number.

--
Fabio Mascarenhas



On Thu, Dec 10, 2009 at 2:23 PM, Sergeant K. <sergeantlu...@gmail.com> wrote:
> That will help me in the right direction, but unfortunately I'm not
> entirely sure how to do this as documentation for LuaSocket isn't
> exactly robust. If a user connects to the server, how do I keep track
> of who is who? Where is their "user id" if it exists already?
>
> On Thu, Dec 10, 2009 at 10:17 AM, Fabio Mascarenhas <mascaren...@acm.org> 
> wrote:
>> Well, you will need to keep a map of users to their connections
>> (sockets) if you want to write a chat server (as well as sets of users
>>  for each group). If you need to send a message to all users belonging
>> to a specific group you do something like this:
>>
>> for _, user_id in ipairs(groups[group_id]) do
>>  sockets[user_id]:send(msg)
>> end
>>
>> This is really indepedent of Copas, Copas will just guarantee that if
>> one of those sends blocks the other parts server will continue working
>> instead of blocking too.
>
> _______________________________________________
> Kepler-Project mailing list
> Kepler-Project@lists.luaforge.net
> http://lists.luaforge.net/cgi-bin/mailman/listinfo/kepler-project
> http://www.keplerproject.org/
>

_______________________________________________
Kepler-Project mailing list
Kepler-Project@lists.luaforge.net
http://lists.luaforge.net/cgi-bin/mailman/listinfo/kepler-project
http://www.keplerproject.org/

Reply via email to