WebSocket


CLASS

WebSocket

Swift
1public final class WebSocket: NSObject, WebSocketClient, StreamDelegate, WebSocketStreamDelegate

Properties

delegate

Swift
1public weak var delegate: WebSocketClientDelegate?

Responds to callback about new messages coming in over the WebSocket and also connection/disconnect messages.

callbackQueue

Swift
1public var callbackQueue = DispatchQueue.main

onConnect

Swift
1public var onConnect: (() -> Void)?

onDisconnect

Swift
1public var onDisconnect: ((Error?) -> Void)?

onText

Swift
1public var onText: ((String) -> Void)?

onData

Swift
1public var onData: ((Data) -> Void)?

onPong

Swift
1public var onPong: ((Data?) -> Void)?

onHttpResponseHeaders

Swift
1public var onHttpResponseHeaders: (([String: String]) -> Void)?

disableSSLCertValidation

Swift
1public var disableSSLCertValidation = false

overrideTrustHostname

Swift
1public var overrideTrustHostname = false

desiredTrustHostname

Swift
1public var desiredTrustHostname: String? = nil

sslClientCertificate

Swift
1public var sslClientCertificate: SSLClientCertificate? = nil

enableCompression

Swift
1public var enableCompression = true

security

Swift
1public var security: SSLTrustValidator?

enabledSSLCipherSuites

Swift
1public var enabledSSLCipherSuites: [SSLCipherSuite]?

isConnected

Swift
1public var isConnected: Bool

request

Swift
1public var request: URLRequest

currentURL

Swift
1public var currentURL: URL

respondToPingWithPong

Swift
1public var respondToPingWithPong: Bool = true

Methods

init(request:protocol:)

Swift
1public init(request: URLRequest, protocol: WSProtocol)

Designated initializer.

  • Parameters:

    • request: A URL request object that provides request-specific information such as the URL.

    • protocol: Protocol to use for communication over the web socket.

Parameters

NameDescription
requestA URL request object that provides request-specific information such as the URL.
protocolProtocol to use for communication over the web socket.

init(url:protocol:)

Swift
1public convenience init(url: URL, protocol: WSProtocol)

Convenience initializer to specify the URL and web socket protocol.

  • Parameters:

    • url: The destination URL to connect to.

    • protocol: Protocol to use for communication over the web socket.

Parameters

NameDescription
urlThe destination URL to connect to.
protocolProtocol to use for communication over the web socket.

init(url:writeQueueQOS:protocol:)

Swift
1public convenience init(
2  url: URL,
3  writeQueueQOS: QualityOfService,
4  protocol: WSProtocol
5)

Convenience initializer to specify the URL and web socket protocol with a specific quality of service on the write queue.

  • Parameters:

    • url: The destination URL to connect to.

    • writeQueueQOS: Specifies the quality of service for the write queue.

    • protocol: Protocol to use for communication over the web socket.

Parameters

NameDescription
urlThe destination URL to connect to.
writeQueueQOSSpecifies the quality of service for the write queue.
protocolProtocol to use for communication over the web socket.

connect()

Swift
1public func connect()

Connect to the WebSocket server on a background thread.

disconnect()

Swift
1public func disconnect()

write(string:)

Swift
1public func write(string: String)

write(ping:completion:)

Swift
1public func write(ping: Data, completion: (() -> ())? = nil)

Write a ping to the websocket. This sends it as a control frame.

newBytesInStream()

Swift
1public func newBytesInStream()

Delegate for the stream methods. Processes incoming bytes

streamDidError(error:)

Swift
1public func streamDidError(error: Error?)

deinit

Swift
1deinit
Feedback

Edit on GitHub

Forums