Server Options
Options are passed to the server at two stages:
WebsocketServer
constructorserve
method
using SimpleWebsockets
server = WebsocketServer([; serverOptions...])
# ...
serve(server[, port, host; socketOptions...])
serverOptions
Overrides the default serverConfig
SimpleWebsockets.serverConfig
— ConstantThe default options for WebsocketServer
false::Union{Bool, Function}
Provide a function with one parametre to check authentication. Must return Bool
.
false::Bool
Whether to use ssl on the server.
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.
"./snakeoil/snakeoil.crt"::String
(default is in the SimpleWebsockets module dir, otherwise provide an absolute path)
Absolute path to your ssl cert
"./snakeoil/snakeoil.key"::String
(default is in the SimpleWebsockets module dir, otherwise provide an absolute path)
Absolute path to your ssl key
64 * 0x0400::Integer
64KiB
The maximum frame size that the server will accept
1 * 0x100000::Integer
1MiB
The maximum assembled message size that the server will accept
true::Bool
Outgoing frames are fragmented if they exceed the set threshold.
16 * 0x0400::Integer
16KiB
Outgoing frames are fragmented if they exceed this threshold.
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.
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.
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.
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
This setting only has an affect as of Julia 1.3
false::Bool
Use Array{UInt8, 1} instead of String as messaging format.
socketOptions
TCP
options to pass into the underlying HTTP.Servers.listen
Handy options:
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)
::Bool
Turns on some helful logging.
This uses the the underlying HTTP
mechanism, which has been observed to misreport the port number.
Please use serverConfig
.ssl options instead of passing options to HTTP.Servers.listen.