WebSockex v0.1.1 WebSockex.Conn

Handles establishing and controlling the TCP connection.

Dispatches to the correct module for the underlying connection. (:gen_tcp or :ssl)

Is woefully inadequite for verifying proper peers in SSL connections.

Summary

Functions

Builds the request to be sent along the newly opened socket

Closes the socket and returns the Conn map without the socket

Waits for the request response, decodes the packet, and returns the response headers

Returns a new WebSockex.Conn struct from a uri and options

Opens a socket to a uri and returns a conn struct

Sets the socket to active

Sends data using the conn_mod module

Waits for the server to close the connection

Types

certification()
certification() :: :public_key.der_encoded
connection_option()
connection_option ::
  {:extra_headers, [header]} |
  {:cacerts, [certification]} |
  {:insecure, boolean}
header()
header() :: {field :: String.t, value :: String.t}
socket()
socket() :: :gen_tcp.socket | :ssl.sslsocket
t()
t() :: %WebSockex.Conn{cacerts: term, conn_mod: :gen_tcp | :ssl, extra_headers: [header], host: String.t, insecure: term, path: String.t | nil, port: non_neg_integer, query: String.t | nil, socket: socket, transport: transport}
transport()
transport() :: :tcp | :ssl

Functions

build_request(conn, key)
build_request(WebSockex.Conn.t, key :: String.t) :: {:ok, String.t}

Builds the request to be sent along the newly opened socket.

The key parameter is part of the websocket handshake process.

close_socket(conn)

Closes the socket and returns the Conn map without the socket.

When the :socket field is nil in the struct, the function just returns the struct as is.

handle_response(conn)
handle_response(WebSockex.Conn.t) ::
  {:ok, [header]} |
  {:error, reason :: term}

Waits for the request response, decodes the packet, and returns the response headers.

Sends any access information in the buffer back to the process as a message to be processed.

new(uri, opts \\ [])

Returns a new WebSockex.Conn struct from a uri and options.

open_socket(conn)
open_socket(WebSockex.Conn.t) ::
  {:ok, WebSockex.Conn.t} |
  {:error, term}

Opens a socket to a uri and returns a conn struct.

set_active(conn, val \\ true)
set_active(WebSockex.Conn.t, true | false) ::
  :ok |
  {:error, reason :: term}

Sets the socket to active.

socket_send(conn, message)
socket_send(WebSockex.Conn.t, binary) ::
  :ok |
  {:error, reason :: term}

Sends data using the conn_mod module.

wait_for_tcp_close(conn, timeout \\ 5000)
wait_for_tcp_close(WebSockex.Conn.t, integer) :: WebSockex.Conn.t

Waits for the server to close the connection.

Returns the Connection without the socket.

The spec says the server should close the TCP connection and the client should wait. I don’t know how long we should wait but 5 seconds seems good.