Notify events
The Notify events enables bi-directional, event-based communication between clients and servers. This allows both sides to send and receive notifications without waiting for a response.
Server-Side Example (Rust)
Let's walk through a basic "Ping-Pong" example, where the client sends a
"ping"
notification to the server, and the server responds with a "pong"
echoing back the same data received.
Client-Side Example (JavaScript)
The socket.on(<eventName>)
method returns an asynchronous iterator, allowing
you to use a for await
loop to continuously listen for events as they arrive:
Sending a Notification
socket.notify(<eventName>, <data>)
sends a notification message to the server
without waiting for a response.
-
<eventName>: string
: The name of the event you want to send. This string identifies the type of notification (e.g.,"ping"
,"update"
, etc.), -
<data>: Uint8Array | string
: The data associated with the event. It can either be:- A array of byte (
Uint8Array
). - A
string
, which will be encoded to UTF-8 bytes before being transmitted.
- A array of byte (