The websocket_server module provides functions for communicating using the WebSocket protocol.
The following code fragment provides a simple example of a echo server:
-module(echo_handler).
-compile(export_all).
-import(websocket_server, [unicast/2]).
go() ->
websocket_server:start("localhost", 9000, ?MODULE, default_echo_handler, []).
default_echo_handler() ->
receive
{message, Data, ConnectionID} ->
unicast(Data, ConnectionID),
default_echo_handler();
_Any -> default_echo_handler()
end.ip_address() see inet(3)
Types:
Starts the WebSocket simple echo server. This function calls start("localhost", 9000, ?MODULE, default_echo_handler, []).
start(Host, Port, Module, Handler, Args) -> void()
Types:
Starts the WebSocket server on port Port as host Host, handler Module:Handler with args Args.
unicast(Data, ConnectionID) -> void()
Types:
Send the data Data to the client whose id is ConnectionID.
broadcast(Data, ConnectionID) -> void()
Types:
Send the data Data to all the clients excluding the one whose id is ConnectionID.
Types:
Send the data Data to all the clients connected.