Guava.Socket (Guava v0.34.0)

Copy Markdown View Source

A reliable, self-reconnecting GuavaSocket connection.

Wraps a WebSocket connection and drives the pure reliable-protocol state machine (Guava.Socket.Reliable). It performs the open/open-ack handshake, retransmits unacked messages across reconnects, keeps the connection alive with pings, and reconnects with backoff — mirroring the Python GuavaSocket.

Messages delivered to the owner

  • {:guava_socket, pid, :ready} — handshake complete, socket open
  • {:guava_socket, pid, {:payload, map}} — an inbound payload arrived
  • {:guava_socket, pid, {:closed, reason, description}} — permanently closed

Summary

Functions

Returns a specification to start this module under a supervisor.

Close the socket permanently.

Enqueue a payload map to send to the peer (buffered until deliverable).

Start a socket.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close(pid)

@spec close(pid()) :: :ok

Close the socket permanently.

send_payload(pid, payload)

@spec send_payload(pid(), map()) :: :ok

Enqueue a payload map to send to the peer (buffered until deliverable).

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Start a socket.

Options

  • :name — a label for logging (string)
  • :url — the ws(s):// URL to connect to
  • :headers — auth/identification headers (list of {k, v})
  • :owner — pid to deliver events to (defaults to the caller)
  • :max_age_ms — optionally close the socket after this many ms