Send a message over a websocket. The following terms are allowed
for Message:
- text(+Text)
- Send a text message. Text is serialized using write/1.
- binary(+Content)
- As
text(+Text)
, but all character codes produced by Content
must be in the range [0..255]. Typically, Content will be
an atom or string holding binary data.
- prolog(+Term)
- Send a Prolog term as a text message. Text is serialized
using write_canonical/1.
- json(+JSON)
- Send the Prolog representation of a JSON term using
json_write_dict/2.
- string(+Text)
- Same as
text(+Text)
, provided for consistency.
- close(+Code, +Text)
- Send a close message. Code is 1000 for normal close. See
websocket documentation for other values.
- Dict
- A dict that minimally contains an
opcode
key. Other keys
used are:
- format:Format
- Serialization format used for Message.data. Format is
one of
string
, prolog
or json
. See ws_receive/3.
- data:Term
- If this key is present, it is serialized according
to Message.format. Otherwise it is serialized using
write/1, which implies that string and atoms are just
sent verbatim.
Note that ws_start_message/3 does not unlock the stream. This is
done by ws_send/1. This implies that multiple threads can use
ws_send/2 and the messages are properly serialized.
- To be done
- - Provide serialization details using options.