Module websocket
websocket API.
Description
The functions in this module are currently only implemented for the emscripten platform.
Data Types
ready_state()
ready_state() = connecting | open | closing | closed
websocket()
abstract datatype: websocket()
Function Index
buffered_amount/1 | Returns the number of bytes of application data that have been queued
using send/2 but not yet been transmitted to the network. |
close/1 | Close websocket. |
close/2 | Close websocket. |
close/3 | Close websocket. |
controlling_process/2 | Set the controlling process of the websocket. |
extensions/1 | Returns the extensions selected by the server, if any. |
is_supported/0 | Determine if websockets are supported in the current environment (browser). |
new/1 | Open a new websocket with the given server. |
new/2 | Open a new websocket with the given server. |
new/3 | Open a new websocket with the given server. |
protocol/1 | Returns the subprotocol selected by the server, if any. |
ready_state/1 | Returns the state of the websocket connection. |
send_binary/2 | Send data to the websocket. |
send_utf8/2 | Send data to the websocket. |
url/1 | Returns the URL that was used to open the websocket. |
Function Details
buffered_amount/1
buffered_amount(Websocket::websocket()) -> non_neg_integer()
Websocket
: websocket to get the buffered amount of
returns: a number of bytes
Returns the number of bytes of application data that have been queued
using send/2
but not yet been transmitted to the network.
close/1
close(Websocket::websocket()) -> ok
Websocket
: websocket to close
returns: ok
Equivalent to close(Websocket, CLOSE_STATUS_CODE_NORMAL, [])
.
Close websocket
close/2
close(Websocket::websocket(), StatusCode::integer()) -> ok
Websocket
: websocket to closeStatusCode
: status code to send to server
returns: ok
Equivalent to close(Websocket, StatusCode, [])
.
Close websocket
close/3
close(Websocket::websocket(), StatusCode::integer(), Reason::iodata()) -> ok
Websocket
: websocket to closeStatusCode
: status code to send to serverReason
: reason to send to server
returns: ok
Close websocket
controlling_process/2
controlling_process(Websocket::websocket(), ControllingProcess::pid()) -> ok | {error, not_owner | badarg | closed}
Websocket
: websocket to set the controlling process forControllingProcess
: Process that gets messages from the websocket
returns: ok
or an error tuple
Set the controlling process of the websocket. Can only be called from the current owner of the websocket.
extensions/1
extensions(Websocket::websocket()) -> unicode:chardata()
Websocket
: websocket to get the extensions of
returns: the websocket extensions
Returns the extensions selected by the server, if any.
is_supported/0
is_supported() -> boolean()
returns: true
if websockets are supported
Determine if websockets are supported in the current environment (browser).
new/1
new(URL::iodata()) -> websocket()
Equivalent to new(URL, <<"binary,base64">>, self())
.
Open a new websocket with the given server.
new/2
new(URL::iodata(), Protocols::[iodata()]) -> websocket()
Equivalent to new(URL, Protocols, self())
.
Open a new websocket with the given server.
new/3
new(URL::iodata(), Protocols::[iodata()], ControllingProcess::pid()) -> websocket()
URL
: URL to connect toProtocols
: List of protocol strings for negociation
with the server.ControllingProcess
: Process that gets messages from the websocket
returns: a websocket resource
Open a new websocket with the given server.
protocol/1
protocol(Websocket::websocket()) -> unicode:chardata()
Websocket
: websocket to get the protocol of
returns: the websocket protocol
Returns the subprotocol selected by the server, if any.
ready_state/1
ready_state(Websocket::websocket()) -> ready_state()
Websocket
: websocket to get the ready state of
returns: the ready state of the socket
Returns the state of the websocket connection.
send_binary/2
send_binary(Websocket::websocket(), Data::iodata()) -> ok | {error, closed}
Websocket
: websocket to send data toData
: data to send
returns: ok
or an error tuple.
Send data to the websocket.
send_utf8/2
send_utf8(WebSocket::websocket(), String::iodata()) -> ok | {error, closed}
String
: string to send
returns: ok
or an error tuple.
Send data to the websocket.
url/1
url(Websocket::websocket()) -> unicode:chardata()
Websocket
: websocket to get the URL of
returns: the websocket URL
Returns the URL that was used to open the websocket