WebSocketService
public protocol WebSocketService : AnyObject
The WebSocketService protocol is implemented by classes that wish to be WebSocket server side
end points. An instance of the WebSocketService protocol is the server side of a WebSocket connection.
There can be many WebSocket connections connected to a single WebSocketService protocol instance.
The protocol is a set of callbacks that are invoked when various events occur.
-
Called when a WebSocket client connects to the server and is connected to a specific
WebSocketService.Declaration
Swift
func connected(connection: WebSocketConnection)Parameters
connectionThe
WebSocketConnectionobject that represents the client’s connection to thisWebSocketService -
Called when a WebSocket client disconnects from the server.
Declaration
Swift
func disconnected(connection: WebSocketConnection, reason: WebSocketCloseReasonCode)Parameters
connectionThe
WebSocketConnectionobject that represents the connection that was disconnected from thisWebSocketService.reasonThe
WebSocketCloseReasonCodethat describes why the client disconnected. -
Called when a WebSocket client sent a binary message to the server to this
WebSocketService.Declaration
Swift
func received(message: Data, from: WebSocketConnection)Parameters
messageA Data struct containing the bytes of the binary message sent by the client.
clientThe
WebSocketConnectionobject that represents the connection over which the client sent the message to thisWebSocketService -
Called when a WebSocket client sent a text message to the server to this
WebSocketService.Declaration
Swift
func received(message: String, from: WebSocketConnection)Parameters
messageA String containing the text message sent by the client.
clientThe
WebSocketConnectionobject that represents the connection over which the client sent the message to thisWebSocketService -
connectionTimeoutDefault implementationThe time in seconds that a connection must be unresponsive to be automatically closed by the server. If the WebSocket server has not received any messages in the first half of the timeout time it will ping the connection. If a pong is not received in the remaining half of the timeout, the connection will be closed with a 1006 (connection closed abnormally) status code. The
connectionTimeoutdefaults tonil, meaning no connection cleanup will take place.Default Implementation
Default computed value for
connectionTimeoutthat returnsnil.Declaration
Swift
var connectionTimeout: Int? { get }
View on GitHub
WebSocketService Protocol Reference