Server Options

Options are passed to the server at two stages:

using SimpleWebsockets

server = WebsocketServer([; serverOptions...])
# ...
serve(server[, port, host; socketOptions...])

serverOptions

Overrides the default serverConfig

SimpleWebsockets.serverConfigConstant

The default options for WebsocketServer

authfunction

false::Union{Bool, Function}

Provide a function with one parametre to check authentication. Must return Bool.

See Http request validation.

ssl

false::Bool

Whether to use ssl on the server.

Warning

Due to an underlying issue in HTTP, a client calling ws:// on a wss::// server will cause the server to error and close. Ensure that only ssl traffic can reach your server port.

sslcert

"./snakeoil/snakeoil.crt"::String (default is in the SimpleWebsockets module dir, otherwise provide an absolute path)

Absolute path to your ssl cert

sslkey

"./snakeoil/snakeoil.key"::String (default is in the SimpleWebsockets module dir, otherwise provide an absolute path)

Absolute path to your ssl key

maxReceivedFrameSize

64 * 0x0400::Integer 64KiB

The maximum frame size that the server will accept

maxReceivedMessageSize

1 * 0x100000::Integer 1MiB

The maximum assembled message size that the server will accept

fragmentOutgoingMessages

true::Bool

Outgoing frames are fragmented if they exceed the set threshold.

fragmentationThreshold

16 * 0x0400::Integer 16KiB

Outgoing frames are fragmented if they exceed this threshold.

closeTimeout

5::Int

The number of seconds to wait after sending a close frame for an acknowledgement to return from the client. Will force close the client if timed out.

keepaliveTimeout

20::Union{Int, Bool}

The interval in number of seconds to solicit each client with a ping / pong response. The client will be closed if no pong is received within the interval.

The timer is only active when no data is received from the client within the interval, ie. the client will only be pinged if inactive for a period longer than the interval.

false to disable.

Warning

Due to an underlying issue with HTTP, a server network disconnect will cause all clients to block in their listen loop, only registering disconnect when the network re-connects.

keepaliveTimeout uses ping/pong and will register the client disconnects more efficiently in network outage events.

useNagleAlgorithm

false::Bool

The Nagle Algorithm makes more efficient use of network resources by introducing a small delay before sending small packets so that multiple messages can be batched together before going onto the wire. This however comes at the cost of latency, so the default is to disable it. If you don't need low latency and are streaming lots of small messages, you can change this to true

Julia 1.3

This setting only has an affect as of Julia 1.3

binary

false::Bool

Use Array{UInt8, 1} instead of String as messaging format.

source

socketOptions

TCP options to pass into the underlying HTTP.Servers.listen

Handy options:

tcpisvalid

Implement connection filtering

Example using Sockets.getpeername:

    using SimpleWebsockets, Sockets
    function tcpisvalid(tcp::Union{MbedTLS.SSLContext, Sockets.TCPSocket})::Bool
        local ipaddress
        try
            ipaddress = Sockets.getpeername(tcp)
        catch
            ipaddress = Sockets.getpeername(tcp.bio) # for MbedTLS.SSLContext
        end
        # (ip"127.0.0.1", 0xd940)
        # Do your CORS, rate filtering, etc. logic here
        # return ::Bool
    end
    serve(server; tcpisvalid = tcpisvalid)
verbose

::Bool

Turns on some helful logging.

Warning

This uses the the underlying HTTP mechanism, which has been observed to misreport the port number.

sslconfig

Please use serverConfig.ssl options instead of passing options to HTTP.Servers.listen.