Cheetah: Keeping track of multiple connected clients
bauss via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue May 16 10:49:07 PDT 2017
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
More information about the Digitalmars-d-learn
mailing list