Class
WebSocket
final class WebSocket
Topics
Structures
struct ConfigurationStores configuration for a WebSocket client/server instance
Instance Properties
var closeCode: WebSocketErrorCode?var eventLoop: any EventLoopvar isClosed: Boolvar onClose: EventLoopFuture<Void>var pingInterval: TimeAmount?If set, this will trigger automatic pings on the connection. If ping is not answered before the next ping is sent, then the WebSocket will be presumed inactive and will be closed automatically. These pings can also be used to keep the WebSocket alive if there is some other timeout mechanism shutting down inactive connections, such as a Load Balancer deployed in front of the server.
Instance Methods
func close(code:)func close(code: WebSocketErrorCode, promise: EventLoopPromise<Void>?)func onBinary(_:)func onPing(_:)func onPong(_:)func onText(_:)func send(_:)func send(ByteBuffer, opcode: WebSocketOpcode, fin: Bool, promise: EventLoopPromise<Void>?)Send the provided data in a WebSocket frame.func send(_:promise:)func send<Data>(raw: Data, opcode: WebSocketOpcode, fin: Bool) async throwsfunc send<Data>(raw: Data, opcode: WebSocketOpcode, fin: Bool, promise: EventLoopPromise<Void>?)func sendPing() async throwsfunc sendPing(Data) async throwsfunc sendPing(Data, promise: EventLoopPromise<Void>?)func sendPing(promise: EventLoopPromise<Void>?)
Type Methods
static func client(on: any Channel, config: WebSocket.Configuration, onUpgrade: (WebSocket) -> ()) -> EventLoopFuture<Void>Sets up a channel to operate as a WebSocket client.static func client(on: any Channel, onUpgrade: (WebSocket) -> ()) -> EventLoopFuture<Void>Sets up a channel to operate as a WebSocket client.static connect(scheme:host:port:path:query:headers:configuration:on:onUpgrade:)Establish a WebSocket connection.static func connect(scheme: String, host: String, port: Int, path: String, query: String?, headers: HTTPHeaders, proxy: String?, proxyPort: Int?, proxyHeaders: HTTPHeaders, proxyConnectDeadline: NIODeadline, configuration: WebSocketClient.Configuration, on: any EventLoopGroup, onUpgrade: (WebSocket) -> ()) -> EventLoopFuture<Void>Establish a WebSocket connection via a proxy server.static connect(to:headers:configuration:on:onUpgrade:)Establish a WebSocket connection.static func connect(to: String, headers: HTTPHeaders, proxy: String?, proxyPort: Int?, proxyHeaders: HTTPHeaders, proxyConnectDeadline: NIODeadline, configuration: WebSocketClient.Configuration, on: any EventLoopGroup, onUpgrade: (WebSocket) -> ()) -> EventLoopFuture<Void>Descriptionstatic func server(on: any Channel, config: WebSocket.Configuration, onUpgrade: (WebSocket) -> ()) -> EventLoopFuture<Void>Sets up a channel to operate as a WebSocket server.static func server(on: any Channel, onUpgrade: (WebSocket) -> ()) -> EventLoopFuture<Void>Sets up a channel to operate as a WebSocket server.
Relationships
Conforms To
Swift.SendableSwift.SendableMetatype