Websocket Protocol

This document defines the ESHET websocket protocol, which is a simple encapsulation of the generic messages defined in Generic Protocol in websocket messages.

One generic message is translated by calling to_json(Message), encoding the result as JSON, and sending it as one websocket text message.

As in the binary protocol, errors (see Errors) are handled by closing the connection.

The conventions used in this document are descried in Conventions.

Message Mangling

Given a message, to_json converts it to a structure which can be json-encoded.

% convert internal message format to json
to_json(Message) ->
    eshet_common:format_json(mangle_message(Message)).

eshet_common:format_json applies the following transformations:

  • Tuples are converted to lists.

  • Atoms (except true, false and none) are converted to strings.

mangle_message applies other necessary transformations, currently only converting the time in reply_state_t() to floating point seconds.

% convert time format to floating point seconds
mangle_message({reply_state, Id, {ok, Value, T}}) ->
    TS = T / erlang:convert_time_unit(1, second, native),
    {reply_state, Id, {ok, Value, TS}};
mangle_message(Message) ->
    Message.

The end result is that a generic message like

{reply, 42, {ok, true}}

becomes

["reply", 42, ["ok", true]]