fix reconnect
This commit is contained in:
parent
7e0549611f
commit
16fd043632
@ -103,18 +103,21 @@ class SocketEngine: NSObject, SRWebSocketDelegate {
|
||||
|
||||
NSURLConnection.sendAsynchronousRequest(reqPolling, queue: self.pollingQueue) {[weak self] res, data, err in
|
||||
var err:NSError?
|
||||
|
||||
if self == nil || err != nil || data == nil {
|
||||
if self == nil {
|
||||
return
|
||||
} else if err != nil || data == nil {
|
||||
println("Error")
|
||||
println(err)
|
||||
exit(1)
|
||||
if !self!.client.reconnecting {
|
||||
self?.client.tryReconnect(triesLeft: self!.client.reconnectAttempts)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
let sub = data.subdataWithRange(NSMakeRange(5, data.length - 5))
|
||||
|
||||
if let json = NSJSONSerialization.JSONObjectWithData(sub,
|
||||
options: NSJSONReadingOptions.AllowFragments, error: &err) as? NSDictionary {
|
||||
println(json)
|
||||
if let sid = json["sid"] as? String {
|
||||
self?.sid = sid
|
||||
|
||||
|
||||
@ -750,7 +750,7 @@ class SocketIOClient: NSObject {
|
||||
}
|
||||
|
||||
// We lost connection and should attempt to reestablish
|
||||
private func tryReconnect(var #triesLeft:Int) {
|
||||
func tryReconnect(var #triesLeft:Int) {
|
||||
if triesLeft != -1 && triesLeft <= 0 {
|
||||
self.connecting = false
|
||||
self.reconnects = false
|
||||
@ -846,8 +846,4 @@ class SocketIOClient: NSObject {
|
||||
self.tryReconnect(triesLeft: self.reconnectAttempts)
|
||||
}
|
||||
}
|
||||
|
||||
func testEngine() {
|
||||
self.engine.open()
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user