Socket.io-client-swift: How to force stop to reconnect loop?

Created on 28 May 2016  ·  4Comments  ·  Source: socketio/socket.io-client-swift

Hello. Thank you for library.

I socket created with .Reconnects(true) is it possible to stop reconnection when it is required?

attempt 1:

socket.on("reconnectAttempt") { [unowned self] (data, ack) -> Void in
  Log.info("reconnectAttempt: \(data) | status: \(self.socket.status)")
  self.socket.disconnect()
}

It crashed sometimes, in reason for

// line 202 SocketIO/SocketIOClient.swift
public func disconnect() {
        assert(status != .NotConnected, "Tried closing a NotConnected client")

Sometimes it not crashed, but reconnection loop not stops too.

attempt 2: Set socket to nil and recreate it with same settings. Also fails, in reason of old client continue reconnection attempts. In logs i have two countdowns:

SocketConnector.swift:133: reconnectAttempt: [4] 
SocketConnector.swift:133: reconnectAttempt: [3]
SocketConnector.swift:133: reconnectAttempt: [4]  
SocketConnector.swift:133: reconnectAttempt: [2]
SocketConnector.swift:133: reconnectAttempt: [3] 
SocketConnector.swift:133: reconnectAttempt: [1]
SocketConnector.swift:133; reconnectAttempt: [2]
SocketConnector.swift:133: reconnectAttempt: [1]    

I can suppose i use it wrong way in reason of luck theoretical knowledge about sockets. But this lib has api which do not work as expected from it's naming.

Questions:
– What i am doing wrong?
– Is there are way to have automatic reconnection but cancel it in any time?
– According to line 202 SocketIO/SocketIOClient.swift – why is that? Why you can not just ignore disconnect request if socket was not connected? Strictly speaking task already done – no connection. or i miss something?

question

Most helpful comment

try setting socket.reconnects to false

All 4 comments

try setting socket.reconnects to false

Thank you

Did that solve your problem?

Yes, thank you. I am sorry do not mentions that.

Was this page helpful?
0 / 5 - 0 ratings