WebSock

Build StatusDocsHex.pm

WebSock is a specification for apps to service WebSocket connections; you can think of it as 'Plug for WebSockets'. Web servers such as Bandit or Cowboy are expected to implement support for hosting WebSock-based applications (possibly by way of an adapter library such as Plug.Cowboy). WebSocket-aware applications such as Phoenix can then be hosted within a supported web server simply by defining conformance to the WebSock behaviour, in the same manner as how Plug conformance allows their HTTP aspects to be hosted within an arbitrary web server.

The WebSock specification is just that; a specification. There is no actual code in this specification as there is within the Plug specification, largely due to the lower-level nature of WebSockets as compared to HTTP. What you will find here consists of simple interface which dictates conventions about how the lifecycle of a WebSocket connection is managed.

The WebSock behaviour describes the functions that an application must implement in order to be WebSock compliant; it is the equivalent of the Plug interface, but for WebSocket connections. Server implementations are expected to manage the upgrade process to WebSocket connections themselves, based on their specific policy and routing decisions and aided by helper functions within the Plug API (see below for details).

WebSocket Lifecycle

WebSocket connections go through a well defined lifecycle, which is reflected in the shape of the WebSock behaviour:

For more information, consult the docs.

Installation

The websock package can be installed by adding websock to your list of dependencies in mix.exs:

def deps do
[
{:websock, "~> 0.4.0"}
]
end

Documentation can be found at https://hexdocs.pm/websock.

License

MIT