socket断开后,再使用同一个socket重新open会报错,因为SRWebSocket的open方法只能被调用一次,所以我们创建新的socket对象来重连解决这一问题
func webSocket(webSocket: SRWebSocket!, didFailWithError error: NSError!) {
print("WebSocket connect failed.", webSocket.readyState.rawValue)
webSocket.delegate = nil
reconnect()
}
func reconnect() {
let url = NSURL(string: SOCKET_URL)
webSocket = SRWebSocket(URL: url)
webSocket.delegate = self
webSocket.open()
}