-
Notifications
You must be signed in to change notification settings - Fork 425
WebSocket
open class WebSocket : NSObject, StreamDelegate, WebSocketClient, WSStreamDelegate
NSObject
, StreamDelegate
, WebSocketClient
, WSStreamDelegate
Used for setting protocols.
public init(request: URLRequest, protocols: [String]? = nil, stream: WSStream = FoundationStream())
public convenience init(url: URL, protocols: [String]? = nil)
public convenience init(url: URL, writeQueueQOS: QualityOfService, protocols: [String]? = nil)
public static let ErrorDomain = "WebSocket"
public var callbackQueue = DispatchQueue.main
Responds to callback about new messages coming in over the WebSocket and also connection/disconnect messages.
public weak var delegate: WebSocketDelegate?
The optional advanced delegate can be used instead of of the delegate
public weak var advancedDelegate: WebSocketAdvancedDelegate?
Receives a callback for each pong message recived.
public weak var pongDelegate: WebSocketPongDelegate?
public var onConnect: (() -> Void)?
public var onDisconnect: ((Error?) -> Void)?
public var onText: ((String) -> Void)?
public var onData: ((Data) -> Void)?
public var onPong: ((Data?) -> Void)?
public var onHttpResponseHeaders: (([String: String]) -> Void)?
public var disableSSLCertValidation = false
public var overrideTrustHostname = false
public var desiredTrustHostname: String? = nil
public var sslClientCertificate: SSLClientCertificate? = nil
public var enableCompression = true
!((os(Linux)))
-
public var security: SSLTrustValidator?
!((os(Linux)))
-
public var enabledSSLCipherSuites: [SSLCipherSuite]?
public var isConnected: Bool
public var request: URLRequest
public var currentURL: URL
public var respondToPingWithPong: Bool = true
Connect to the WebSocket server on a background thread.
open func connect()
Disconnect from the server. I send a Close control frame to the server, then expect the server to respond with a Close control frame and close the socket from its end. I notify my delegate once the socket has been closed.
open func disconnect(forceTimeout: TimeInterval? = nil, closeCode: UInt16 = CloseCode.normal.rawValue)
If you supply a non-nil forceTimeout
, I wait at most that long (in seconds) for the server to close the socket. After the timeout expires, I close the socket and notify my delegate.
If you supply a zero (or negative) forceTimeout
, I immediately close the socket (without sending a Close control frame) and notify my delegate.
- forceTimeout: Maximum time to wait for the server to close the socket.
- closeCode: The code to send on disconnect. The default is the normal close code for cleanly disconnecting a webSocket.
Write a string to the websocket. This sends it as a text frame.
open func write(string: String, completion: (() -> ())? = nil)
If you supply a non-nil completion block, I will perform it when the write completes.
- string: The string to write.
- completion: The (optional) completion handler.
Write binary data to the websocket. This sends it as a binary frame.
open func write(data: Data, completion: (() -> ())? = nil)
If you supply a non-nil completion block, I will perform it when the write completes.
- data: The data to write.
- completion: The (optional) completion handler.
Write a ping to the websocket. This sends it as a control frame. Yodel a sound to the planet. This sends it as an astroid. http://youtu.be/Eu5ZJELRiJ8?t=42s
open func write(ping: Data, completion: (() -> ())? = nil)
Write a pong to the websocket. This sends it as a control frame. Respond to a Yodel.
open func write(pong: Data, completion: (() -> ())? = nil)
Delegate for the stream methods. Processes incoming bytes
public func newBytesInStream()
public func streamDidError(error: Error?)
Types
- CloseCode
- CocoaMQTT
- CocoaMQTT5
- CocoaMQTT5Message
- CocoaMQTTAUTHReasonCode
- CocoaMQTTCONNACKReasonCode
- CocoaMQTTConnAck
- CocoaMQTTConnState
- CocoaMQTTDISCONNECTReasonCode
- CocoaMQTTError
- CocoaMQTTError.FoundationConnection
- CocoaMQTTLogger
- CocoaMQTTLoggerLevel
- CocoaMQTTMessage
- CocoaMQTTPUBACKReasonCode
- CocoaMQTTPUBCOMPReasonCode
- CocoaMQTTPUBRECReasonCode
- CocoaMQTTPUBRELReasonCode
- CocoaMQTTPropertyName
- CocoaMQTTQoS
- CocoaMQTTSUBACKReasonCode
- CocoaMQTTSocket
- CocoaMQTTUNSUBACKReasonCode
- CocoaMQTTWebSocket
- CocoaMQTTWebSocket.DefaultConnectionBuilder
- CocoaMQTTWebSocket.FoundationConnection
- CocoaMQTTWebSocket.StarscreamConnection
- CocoaRetainHandlingOption
- ErrorType
- FoundationStream
- MqttAuthProperties
- MqttConnectProperties
- MqttDecodeConnAck
- MqttDecodePubAck
- MqttDecodePubComp
- MqttDecodePubRec
- MqttDecodePubRel
- MqttDecodePublish
- MqttDecodeSubAck
- MqttDecodeUnsubAck
- MqttPublishProperties
- MqttSubscription
- PayloadFormatIndicator
- SSLCert
- SSLClientCertificate
- SSLClientCertificateError
- SSLSecurity
- SSLSettings
- WSError
- WebSocket
- WebSocket.OpCode
- WebSocket.WSResponse
- formatInt
Protocols
- CocoaMQTT5Delegate
- CocoaMQTTDelegate
- CocoaMQTTSocketDelegate
- CocoaMQTTSocketProtocol
- CocoaMQTTWebSocketConnection
- CocoaMQTTWebSocketConnectionBuilder
- CocoaMQTTWebSocketConnectionDelegate
- SSLTrustValidator
- WSStream
- WSStreamDelegate
- WebSocketAdvancedDelegate
- WebSocketClient
- WebSocketDelegate
- WebSocketPongDelegate