Module: Perfect-WebSockets
class WebSocket
This class represents the communications channel for a WebSocket session.
enum OpcodeType: UInt8
The various types of WebSocket messages.
case continuation = 0x0,
Continuation op code
case text = 0x1,
Text data indicator
case binary = 0x2,
Binary data indicator
case close = 0x8,
Close indicator
case ping = 0x9,
Ping message
case pong = 0xA,
Ping response message
case invalid
Invalid op code
var readTimeoutSeconds: Double = NetEvent.noTimeout
The read timeout, in seconds. By default this is -1, which means no timeout.
var isConnected: Bool { return self.socket.isValid }
Indicates if the socket is still likely connected or if it has been closed.
func close()
Close the connection.
func sendPong(completion: @escaping () -> ())
Send a "pong" message to the client.
func sendPing(completion: @escaping () -> ())
Send a "ping" message to the client.
Expect a "pong" message to follow.
protocol WebSocketSessionHandler
The protocol that all WebSocket handlers must implement.
var socketProtocol: String? { get }
Optionally indicate the name of the protocol the handler implements.
If this has a valid, the protocol name will be validated against what the client is requesting.
func handleSession(request req: HTTPRequest, socket: WebSocket)
This function is called once the WebSocket session has been initiated.
struct WebSocketHandler
This request handler accepts WebSocket requests from client.
It will initialize the session and then deliver it to the `WebSocketSessionHandler`.
func init(handlerProducer: @escaping HandlerProducer)
Initialize WebSocketHandler with a handler producer function
func handleRequest(request: HTTPRequest, response: HTTPResponse)
Handle the request and negotiate the WebSocket session