DandelionWebSockets.AbstractMatcher
— TypeAbstract type for objects that match actual arguments against expected arguments. For instance, we sometimes don't care what value is provided a mock function, only what type it is. Also, this can be used to parse an actual argument as JSON and compare the resulting object, rather than relying on a string comparison.
All AbstractMatcher
types T
must define a function mock_match(::T, v::Any)
.
DandelionWebSockets.Backoff
— TypeA backoff that follows a atan curve, and reaches about 90% of max backoff in 12 attempts.
DandelionWebSockets.Backoff
— MethodGet the next backoff value.
DandelionWebSockets.ClientProtocol
— TypeType for the logic of a client WebSocket.
DandelionWebSockets.MockCall
— TypeAn expected function call, along with expected arguments, and an action it should perform.
DandelionWebSockets.MockExpectationException
— TypeAn exception thrown when an unexpected argument was found or a function was called.
DandelionWebSockets.RandomizedBackoff
— TypeRandomize another backoff by adding some randomness to the backoff time.
DandelionWebSockets.Retry
— TypeStart a timer for some function, based on a backoff.
DandelionWebSockets.Throws
— TypeTells a mock function that it should throw an exception.
DandelionWebSockets.TypeMatcher
— TypeMatch a value by checking its type only.
DandelionWebSockets.ValueMatcher
— TypeSimply match a value by equality. This is the default.
DandelionWebSockets.WSClient
— TypeA WebSocket client, used to connect to a server, and send messages.
Note: The keyword arguments in the constructor are primarily for testing.
Base.reset
— MethodReset the backoff to its initial state.
DandelionWebSockets.on_binary
— MethodHandle a binary frame.
DandelionWebSockets.on_text
— MethodHandle a text frame.
DandelionWebSockets.send_binary
— MethodSend a single binary frame.
DandelionWebSockets.send_text
— MethodSend a single text frame.
DandelionWebSockets.state_closed
— MethodThe WebSocket was closed.
DandelionWebSockets.state_closing
— MethodThe WebSocket is about to close.
DandelionWebSockets.state_connecting
— MethodThe WebSocket is trying to connect.
DandelionWebSockets.state_open
— MethodThe WebSocket is open and ready to send and receive messages.
DandelionWebSockets.stop
— MethodClose the WebSocket connection.
DandelionWebSockets.wsconnect
— MethodConnect the client to a WebSocket server at uri
, and use handler
for the callbacks.
Arguments
fix_small_message_latency::Bool = false
: Set the TCP_NODELAY flag to improve small message latency.
Fix small message latency
The TCP protocol can buffer small messages (1448 bytes and smaller). The reason is that this reduces the overhead when sending large amounts of small packets. However, it also means that latency can be much higher for small messages. This buffering can be disabled by setting a flag TCPNODELAY. By default, the WebSocket client will now set the TCPNODELAY flag.
If your application will send and receive primarily small messages (1448 bytes or smaller), and it is sensitive to latency, then leave fix_small_message_latency
set to true (now the default). This sets the TCPNODELAY flag. If you are not concerned about latency, but concerned about throughput for many small messages, then you can set `fixsmallmessagelatency = false`. Then you may get higher throughput, at the expense of higher latency for small messages.
DandelionWebSockets.@expect
— MacroExpect a call with some arguments, and perform an action when that call has been made..
DandelionWebSockets.@mock
— MacroDefine a mock type, given a symbol for its name and a type from which it should inherit.
DandelionWebSockets.@mockfunction
— MacroDefine one or more functions that mock the behaviour the object should have.
The functions defined here are the functions called by the code under test. The functions check that their arguments match those that are expected, and that the mock action is performed.
DandelionWebSockets.AbnormalNoCloseResponseReceived
— TypeNo Close frame response was received by the client after a reasonable time
DandelionWebSockets.AbnormalSocketNotClosedByServer
— TypeThe socket did not close the socket in a reasonable timeframe.
DandelionWebSockets.AbstractHandshakeResult
— TypeAbstractHandshakeResult is a supertype for either a successful or an unsuccessful handshake.
DandelionWebSockets.BadHandshake
— TypeBadHandshake is returned when an unsuccessful handshake has been made.
DandelionWebSockets.ClientInitiatedCloseBehaviour
— TypeClosing the WebSocket connection is a procedure for closing the connection during the normal course the protocol lifetime.
DandelionWebSockets.ClientPingRequest
— TypeSend a ping request to the server.
DandelionWebSockets.ClientProtocolInput
— TypeAbstract type for all commands sent to ClientProtocol
.
These commands are sent as arguments to the different handle
functions on ClientProtocol
. Each command represents an action on a WebSocket, such as sending a text frame, ping request, or closing the connection.
DandelionWebSockets.CloseRequest
— TypeA request to close the WebSocket.
DandelionWebSockets.CloseStatus
— TypeCloseStatusCode indicates a reason for closing the connection. It is optionally sent as the first two bytes of a Close frames payload.
DandelionWebSockets.FailTheConnectionBehaviour
— TypeFailing the WebSocket connection is an action taken at certain points in the protocol specification, in response to error conditions.
The closing behaviour is to optionally send a Close frame, with an appropriate status code, and then close the socket.
DandelionWebSockets.FinalFrameAlreadySentException
— TypeFinalFrameAlreadySentException is thrown when sendframe is called again after the last frame.
DandelionWebSockets.FrameFromServer
— TypeA frame was received from the server.
DandelionWebSockets.FrameSender
— TypeFrameSender is used to send multi-frame messages.
You are provided a FrameSender via the client. You then send data using the sendframe(sender, data; isfinal=false)
method. For the last frame you set isfinal = true
.
After the last frame has been sent, you MAY NOT use the FrameSender again. Trying to send another frame with the same instance of FrameSender WILL lead to an exception of type FinalFrameAlreadySentException
.
NOTE: While you have a FrameSender
in which you have not sent the last frame, then you MAY NOT use the client to send any other messages. Interleaving messages is prohibited by the WebSocket protocol and will lead to the socket being closed.
NOTE: You may send frames that are individually invalid UTF-8. However, the complete message, which is all frames concatenated, MUST be valid UTF-8, or the other endpoint is required to fail the WebSocket connection. With the TextFrameSender
you can use both a String
or a Vector{UInt8}
as the payload. The Vector{UInt8}
alternative can be used to send invalid UTF-8, or possibly invalid UTF-8.
Example
sender = sendmultiframetext(client)
sendframe(sender, "Hello")
sendframe(sender, "world")
sendframe(sender, "Goodbye"; isfinal=true)
Example
sender = sendmultiframebinary(client)
sendframe(sender, b"Hello")
sendframe(sender, b"world")
sendframe(sender, b"Goodbye"; isfinal=true)
DandelionWebSockets.FrameWriter
— TypeFrameWriter is used by the protocols to write frames to a socket.
This is separate from the client protocol code, because the protocol for closing a connection is separate from the rest of the client protocol, and both need to send frames.
DandelionWebSockets.GoodHandshake
— TypeGoodHandshake is returned when a successful handshake has been made.
DandelionWebSockets.HTTPAdapter
— TypeHTTPAdapter is an abstract type for an HTTP package that can be used for a handshake GET.
Any subtype of HTTPAdapter should implement the dohandshake
method.
DandelionWebSockets.HTTPHandshake
— TypeHTTPHandshake implements the HTTP handshake from the WebSocket specification.
It requires a random number generator to generate the WebSocket random key used to verify that the other side is actually a WebSocket server. The HTTPAdapter
supplied implements the actual HTTP GET request, which returns an HTTPUpgradeResponse
.
DandelionWebSockets.HTTPUpgradeResponse
— TypeHTTPUpgradeResponse is a collection of data returned by a HTTP upgrade, regardless of package.
DandelionWebSockets.PongMissed
— TypeA pong reply was expected, but never received.
DandelionWebSockets.SendBinaryFrame
— TypeSend a binary frame, sent to ClientProtocol
.
DandelionWebSockets.SendTextFrame
— TypeSend a text frame, sent to ClientProtocol
.
DandelionWebSockets.ServerInitiatedCloseBehaviour
— TypeThe server can initiate a Close, in which case this behaviour ensures a proper close.
DandelionWebSockets.ServerReader
— TypeReading from a network socket and placing the resulting frame on a channel.
DandelionWebSockets.SocketClosed
— TypeUsed when the underlying network socket was closed.
DandelionWebSockets.SocketState
— TypeEnum value for the different states a WebSocket can be in.
DandelionWebSockets.StopTaskException
— TypeAn exception thrown into a task in order to stop it.
DandelionWebSockets.TLSBufferedIO
— TypeTLSBufferedIO adapts a TLS socket so we can do byte I/O.
The stream returned by MbedTLS when using a TLS socket does not support the byte I/O used when reading a frame. It only supports reading a chunk of data. This is a fake stream that buffers some data and lets us do byte I/O.
Note: This should have been done by the BufferedStreams.jl package. However, I couldn't get it to work with the MbedTLS stream, for reasons unknown. If we can investigate and fix that problem, then we should really replace this type with a BufferedInputStream.
DandelionWebSockets.WebSocketHandshake
— TypeWebSocketHandshake represents a way to make a WebSocket connection handshake.
The only handshake detailed in the specification is an HTTP handshake, represented by the HTTPHandshake
type (regardless of HTTP package used to implement it). The specification does mention the possibility of other types of handshakes, even though these would be outside of the specification.
DandelionWebSockets.connection_result_
— MethodThe HTTP Upgrade failed, for whatever reason.
DandelionWebSockets.connection_result_
— Methodconnection_result(::WSClient, ::GoodHandshake, ::WebSocketHandler, fix_small_message_latency::Bool)
For a valid handshake, start all background tasks for this connection. This includes tasks for reading and writing from the socket, as well as a task for user callback.
DandelionWebSockets.do_reader
— MethodRead frames from the network, until an exception is thrown in this task.
DandelionWebSockets.dohandshake
— Methoddohandshake(http::HTTPAdapter, uri::String, headers::HeaderList)
Do an HTTP GET request to uri
including headers headers
.
The headers
list will contain all WebSocket upgrade specific headers, such as Connection
, Upgrade
, and Sec-WebSocket-Key
.
DandelionWebSockets.fill_buffer
— MethodRead all available data, and block until we have enough to fulfíll the next read.
DandelionWebSockets.handle
— MethodHandle a user request to close the WebSocket.
DandelionWebSockets.handle
— MethodHandle a frame from the server.
DandelionWebSockets.handle
— MethodSend a single binary frame.
DandelionWebSockets.handle
— MethodSend a single text frame.
DandelionWebSockets.handle
— MethodThe underlying socket was closed. This is sent by the reader.
DandelionWebSockets.issuccessful
— Methodissuccessful(::AbstractHandshakeResult)
True if a handshake was succcessful, false otherwise.
DandelionWebSockets.name_args_
— MethodDefine a name for an argument, if no name is provided.
DandelionWebSockets.performhandshake
— Methodperformhandshake(h::HTTPHandshake, uri::String)
Do a handshake with the server at uri
, with parameters supplied by h
. Validate the handshake, and return a good or bad result, depending on the validation.
DandelionWebSockets.protocolstate
— MethodThe state of the connection.
DandelionWebSockets.send
— MethodSend a frame to the other endpoint, using the supplied payload and opcode.
DandelionWebSockets.sendframe
— MethodSpecialization of sendframe for TextFrameSender, for sending Strings as data.
DandelionWebSockets.sendframe
— MethodSend a frame with a payload to the other endpoint. isfinal
must be set to true for the last frame.
After the call with isfinal = true
, then this method MAY NOT be called again. If it is, then a FinalFrameAlreadySentException
will be thrown.
DandelionWebSockets.tcpnodelay
— Methodtcpnodelay(::IO)
Sets the TCP_NODELAY flag on a socket. This is a separate function only for testing purposes. It can be implemented with a more specific type if the flag makes no sense for another IO
subtype.