socket.io-client-swift
socket.io-client-swift copied to clipboard
Socket `disconnect` not fired when device loses network
Version 16.0.0
Expected behavior
A connected socket will fire the disconnect event when a device loses network. Or fire any event, like statusChanged or reconnect.
Actual behavior
No disconnect event is emitted until the ping timeout 60 seconds later.
I've tried the following code to get any indication that the socket is no longer connected:
socket.onAny { event in
print("Got event: \(event.event), with items: \(event.items)")
}
socket.connect()
but no event fires when the device loses network until 60 seconds later.
For what it's worth, the Java SocketIO client is connected to the same server and receives a disconnect event immediately upon losing network, so it does not seem to be anything to do with the server configuration.
Hey! Have you setup all parameters related to reconnection? Eg:
let config = [
.log(true),
.forceWebsockets(true),
.reconnects(true),
.reconnectAttempts(5),
.reconnectWait(1),
.reconnectWaitMax(10)
] as SocketIOClientConfiguration
socketManager = SocketManager.init(socketURL: url, config: config)
It's working properly with above config in my case, so I get several reconnect events and then disconnect.
I'm dealing with the same issue. Any update @phansen-nd ?
@miguel-arrf no we ended up using a different network handler because this didn't work.
@miguel-arrf no we ended up using a different network handler because this didn't work.
Oh... @phansen-nd . Thank you anyway!
This seems to still be an issue... network disconnects causing socket failure should emit a disconnect.
*Edit: When a user loses network connection completely, or switches from Wifi to LTE, it takes about 50-60 seconds for the .error event to be emitted from the SocketManager.defaultSocket. In case of switching network type, it will reconnect using the new network type, but at that 50-60 second delay. Can this be changed to be quicker? ie 2 second delay?
@nuclearace can we get some input on this?
@miguel-arrf no we ended up using a different network handler because this didn't work.
Did you use Apple's Network framework to detect changes in network and force reconnect? @miguel-arrf