WebSocketConnection
public class WebSocketConnection
Represents a specific WebSocket connection. Provides a unique identifier for the connection and APIs to send messages and control commands to the client at the other end of the connection.
-
Unique identifier for this
WebSocketConnectionDeclaration
Swift
public let id: String -
The ServerRequest from the original protocol upgrade
Declaration
Swift
public let request: ServerRequest -
Close a WebSocket connection by sending a close control command to the client optionally with the specified reason code and description text.
Declaration
Swift
public func close(reason: WebSocketCloseReasonCode? = nil, description: String? = nil)Parameters
reasonAn optional reason code to send in the close control command describing why the connection was closed. If nil, a reason code of
WebSocketCloseReasonCode.normalwill be sent.descriptionAn optional text description to be sent in the close control frame.
-
Forcefully close a WebSocket connection by sending a close control command to the client optionally with the specified reason code and description text followed by closing the socket.
Declaration
Swift
public func drop(reason: WebSocketCloseReasonCode? = nil, description: String? = nil)Parameters
reasonAn optional reason code to send in the close control command describing why the connection was closed. If nil, a reason code of
WebSocketCloseReasonCode.normalwill be sent.descriptionAn optional text description to be sent in the close control frame.
-
Send a ping control frame to the client
Declaration
Swift
public func ping(withMessage: String? = nil)Parameters
withMessageAn optional string to be included in the ping control frame.
-
Send a message to the client contained in a Data struct.
Declaration
Swift
public func send(message: Data, asBinary: Bool = true)Parameters
messageA Data struct containing the bytes to be sent to the client as a message.
asBinaryIf true, which is the default, the message is sent as a binary mesage. If false, the message will be sent as a text message.
-
Send a text message to the client
Declaration
Swift
public func send(message: String)Parameters
messageA String containing the text to be sent to the client as a text message.
View on GitHub
WebSocketConnection Class Reference