Web sockets make it cheaper to talk to your servers.
Connecting to a server takes some time, so with web sockets, you make that connection once and then keep using. The major benefits of this are:
It faster to send messages. No need to do a bunch of work for every single message.
The server can push messages to you. With normal HTTP you would have to keep asking for changes, but a web socket, the server can talk to you whenever it wants. This means there is less unnecessary network traffic.
The API here attempts to cover the typical usage scenarios, but if you need many unique connections to the same endpoint, you need a different library.
Keep a connection alive, but do not report any messages. This is useful
for keeping a connection open for when you only need to send messages. So
you might say something like this:
subscriptions model =
keepAlive "ws://echo.websocket.org"Note: If the connection goes down, the effect manager tries to reconnect
with an exponential backoff strategy. Any messages you try to send while the
connection is down are queued and will be sent as soon as possible.
Send a message to a particular address. You might say something like this:
send "ws://echo.websocket.org" "Hello!"Note: It is important that you are also subscribed to this address with
listen or keepAlive. If you are not, the web socket will be created to
send one message and then closed. Not good!
Subscribe to any incoming messages on a websocket. You might say something like this:
Note: If the connection goes down, the effect manager tries to reconnect with an exponential backoff strategy. Any messages you try to
sendwhile the connection is down are queued and will be sent as soon as possible.