Skip to content
Strata is pre-1.0. APIs, protocol, and storage format may change.

Erlang and Gun Transport

strata_transport_gun opens a WebSocket through gluegun. It targets Erlang.

import gluegun/connection
import strata_transport_gun as gun
let options =
gun.options()
|> gun.with_secure(True)
|> gun.with_timeout(connection.Milliseconds(10_000))

options() uses a five-second timeout and an insecure TCP connection. with_secure(True) selects TLS.

gun.open_socket(
host: "example.com",
port: 443,
path: "/socket/websocket",
token: token,
options: options,
on_open: on_open,
on_message: on_message,
on_close: on_close,
)

The function appends one percent-encoded token query value to path. Pass the raw token text. The function starts a receive process after the connection opens.

open_socket returns Result(Socket, GluegunError). Handle this result before you store the socket. The close callback receives:

  • Closed after a normal WebSocket close frame;
  • Failed(error) after a receive error.

The receive loop ignores non-text application frames.

send_text and close return Result(Nil, GluegunError). Report an error or start reconnect handling. Do not treat a failed send as a successful edit.