Closed
Description
As I have stated in #470, I am building an app that allows to change the Socket URL at runtime. When the user installs the app there is a default socket URL "http://someurl:9000" with which the app will first try to connect to.
First, here is the method I use to connect/disconnect from the socket:
func connect(socketURL: String) {
socket?.removeAllHandlers()
if (socket?.status != SocketIOClientStatus.notConnected) {
socket?.disconnect()
}
socket = SocketIOClient(socketURL: NSURL(string: socketURL)! as URL, config: [.log(true), .reconnectAttempts(5)])
socket!.connect()
}
If the server isn't available I obviously will get an error.
2016-08-28 10:49:47.158425 MyApp[4033:1536921] LOG SocketEngine: Starting engine. Server: http://localhost:9000
2016-08-28 10:49:47.158533 MyApp[4033:1536921] LOG SocketEngine: Handshaking
2016-08-28 10:49:47.164707 MyApp[4033:1536921] LOG SocketEnginePolling: Doing polling request
2016-08-28 10:49:47.263610 MyApp[4033:1536921] ERROR SocketEnginePolling: Could not connect to the server.
2016-08-28 10:49:47.263810 MyApp[4033:1536921] ERROR SocketEngine: Could not connect to the server.
2016-08-28 10:49:47.263910 MyApp[4033:1536921] ERROR SocketIOClient: Could not connect to the server.
2016-08-28 10:49:47.265005 MyApp[4033:1536921] LOG SocketIOClient: Handling event: error with data: ["Could not connect to the server."]
2016-08-28 10:49:47.265362 MyApp[4033:1536921] LOG SocketIOClient: Starting reconnect
2016-08-28 10:49:47.265535 MyApp[4033:1536921] LOG SocketIOClient: Handling event: reconnect with data: ["Could not connect to the server."]
2016-08-28 10:49:47.265626 MyApp[4033:1536921] LOG SocketIOClient: Trying to reconnect
2016-08-28 10:49:47.265833 MyApp[4033:1536921] LOG SocketIOClient: Handling event: reconnectAttempt with data: [5]
After changing it to a valid URL (look at the time)
2016-08-28 10:50:02.955333 MyApp[4033:1536921] LOG SocketEngine: Starting engine. Server: http://192.168.1.128:9000
2016-08-28 10:50:02.955434 MyApp[4033:1536921] LOG SocketEngine: Handshaking
2016-08-28 10:50:02.955666 MyApp[4033:1536921] LOG SocketEnginePolling: Doing polling request
2016-08-28 10:50:03.815273 MyApp[4033:1536921] LOG SocketEnginePolling: Got polling response
2016-08-28 10:50:03.832388 MyApp[4033:1537062] LOG SocketEngine: Got message: 0{"sid":"bQCyvNHrmtshnKIrAAAE","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}
.
.
.
.
2016-08-28 10:50:08.426368 MyApp[4033:1536921] LOG SocketIOClient: Trying to reconnect
2016-08-28 10:50:08.426796 MyApp[4033:1536921] LOG SocketIOClient: Handling event: reconnectAttempt with data: [3]
2016-08-28 10:50:08.427116 MyApp[4033:1536921] LOG SocketEngine: Starting engine. Server: http://localhost:9000
2016-08-28 10:50:08.427287 MyApp[4033:1536921] LOG SocketEngine: Handshaking
2016-08-28 10:50:08.427922 MyApp[4033:1536921] LOG SocketEnginePolling: Doing polling request
2016-08-28 10:50:08.451308 MyApp[4033:1536921] ERROR SocketEnginePolling: Could not connect to the server.
2016-08-28 10:50:08.451841 MyApp[4033:1536921] ERROR SocketEngine: Could not connect to the server.
2016-08-28 10:50:08.452062 MyApp[4033:1536921] ERROR SocketIOClient: Could not connect to the server.
2016-08-28 10:50:08.452451 MyApp[4033:1536921] LOG SocketIOClient: Handling event: error with data: ["Could not connect to the server."]
How can I gracefully shutdown the first, non-working SocketIOClient? At the moment, disconnect()
doesn't shut it down properly until reconnect attempts is at zero.
Is it the same issue we're facing here like this one: socketio/socket.io-client#737?