On Tuesday, 16 May 2017 at 17:49:07 UTC, bauss wrote:
On Tuesday, 16 May 2017 at 16:01:49 UTC, aberba wrote:
Does anyone know how to keep track of multiple clients in Cheetah socket lib such that one can directly message a client or broadcast to all connected clients.


Something like:

onMessage(... e)
{
...
   // send to all
   e.clients.broadcast (message);

...OR...
   // target a client
    e.clients[clientID].send(message);
}

Or any D lib with similar function.

I have now added an internal client-storage to the project.

The server will have a getClientById(size_t) and a getClients() which can be used.

Ex.

foreach (client; e.server.getClients())  {
    // ... Broadcast to each client here
}

...

e.server.getClientById(clientId).send(...);

Each client will be attached to a clientId when they connect.

The client id is a property of the SocketClient class.

To enable the internal storage you must set storeClients to true on the server when initializing it, otherwise the storage won't be used.

Ex.

server.storeClients = true;

If you don't want to get latest version of it, then you can just make your own storage ex. an associative array and then add each client to it when they connect.

Right now dub doesn't seem to be able to trigger a manual update on the package, so you might have to fetch the updates manually from the Github repository.

https://github.com/bausshf/cheetah/commit/9646fd407d274a94c37dc1b0297541963aeb3e6d

It really awesome the way you responded quickly. About targeting a client, suppose I have clients A, B, and C.

Message can be broadcast to all using above solution. But in case A want to sent message to B and not C, how does server detect the specific destination client's id? Does client.send(...) allow json string with target id from browser client?

I'm trying to find a way to receive meesage in one language along with target client's id and send to the target after I have translated to another lang.

Reply via email to