Turn a raw TCP/IP (or any other binary stream) into a websocket
stream. Stream can be an input stream, output stream or a stream
pair. Options includes
- mode(+Mode)
- One of
server
or client
. If client
, messages are sent
as masked.
- buffer_size(+Count)
- Send partial messages for each Count bytes or when flushing
the output. The default is to buffer the entire message before
it is sent.
- close_parent(+Boolean)
- If
true
(default), closing WSStream also closes Stream.
- subprotocol(+Protocol)
- Set the subprotocol property of WsStream. This value can be
retrieved using ws_property/2. Protocol is an atom. See
also the
subprotocols
option of http_open_websocket/3 and
http_upgrade_to_websocket/3.
A typical sequence to turn a pair of streams into a WebSocket is
here:
...,
Options = [mode(server), subprotocol(chat)],
ws_open(Input, WsInput, Options),
ws_open(Output, WsOutput, Options),
stream_pair(WebSocket, WsInput, WsOutput).