Swift中的Socket客户端:SocketIOCocoa

分享到:

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?)
}

项目主页:http://www.open-open.com/lib/view/home/1416236682836

昵    称:
验证码:

相关文档: