Swift中的Socket客户端:SocketIOCocoa
jopen
10年前
SocketIOCocoa 是Swift中的Socket客户端,包含了 xhr polling 和 websocket transports。
这是socketio.client一个移植,这意味着代码结构是非常相似的。Swift
Create a client
var client = SocketIOClient(uri: uri, reconnect: true, timeout: 30) client.open()
Create a socket
var socket = client.socket("namespace") // Set a delegate on socket
The SocketIOSocketDelegate
@objc public protocol SocketIOSocketDelegate { // Called when the socket received a low level packet optional func socketOnPacket(socket: SocketIOSocket, packet: SocketIOPacket) // Called when the socket received an event func socketOnEvent(socket: SocketIOSocket, event: String, data: AnyObject?) // Called when the socket is open func socketOnOpen(socket: SocketIOSocket) // Called when the socket is on error func socketOnError(socket: SocketIOSocket, error: String, description: String?) }