Websocket Client

Provides a Websocket client compatible with Websocket versions [8, 13]

Currently does not support Websocket Extensions

Minimum required usage:

using SimpleWebsockets

client = WebsocketClient()

listen(client, :connect) do ws::WebsocketConnection #must be called before `open`
    #...
end

open(client, "ws://url.url")

Constructor

Client Methods

Base.openMethod
open(client::WebsocketClient, url::String [, headers::Dict{String, String}; options...])

Open a new websocket client connection at the given url. Blocks until the connection is closed.

Optionally provide custom headers for the http request.

; options... are passed to the underlying HTTP.request

source
Base.isopenMethod
isopen(client::WebsocketClient)::Bool

Returns a Bool indication if the client TCP connection is open.

source

Client Events

Client event callback functions are registered using the listen method.

SimpleWebsockets.listenMethod
listen(callback::Function, client::SimpleWebsockets.WebsocketClient, event::Symbol)

Register event callbacks onto a client. The callback must be a function with exactly one argument.

Valid events are:

  • :connect
  • :connectError

Example

listen(client, :connect) do ws
    #...
end
source
:connect

Triggered when the client has successfully connected to the server

Returns a WebsocketConnection to the callback.

listen(client, :connect) do ws::SimpleWebsockets.WebsocketConnection
    #...
end
:connectError

Triggered when an attempt to open a client connection fails

listen(client, :connectError) do err::WebsocketError.ConnectError
    # err.msg::String
    # err.log::Function > logs the error message with stack trace
end