Skip to main content
Version: 2.1.x

Sending data

Send data to a specific client

Send

You are able to send data to the client. The data can be any amount of variables of any type. When the data is sent, it will trigger the corresponding client-side MessageHandler.

Syntax

send(eventHandlerName: string, ...data: any[])
server.send(socket, "Example name", "myData", true);

OR

socket.send("Example name", "myData", true);

Waiter

Waiters can be used to simply send data too, but it is not practical to do so.

Syntax

waiter<T>(socket: ZilaConnection, eventHandlerName: string, ...data: any[]) : Promise<T | undefined>
const response: string | undefined = await server.waiter<string>(socket, "Example name", "myData", true);

OR

const response: string | undefined = await socket.waiter<string>("Example name", "myData", true);

Broadcasting

Sometimes you need to send a message to all the clients. Don't worry, ZilaWS got you covered.

Send

Unlike waiters, this will return void and is not awaitable.

server.broadcastSend("Broadcast Example", "Broadcast data");

Waiter

You might use waiters, if you're expecting to receive back data or just want to make sure the client did what you asked it for.

const responses: Array<string | undefined> = 
await server.broadcastWaiter<string>("Waiter Broadcast Example", "Broadcast data");