socketio / socket.io-client-swift

Other
5.22k stars 843 forks source link

Socket `disconnect` not fired when device loses network #1415

Open phansen-nd opened 2 years ago

phansen-nd commented 2 years ago

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.

msobiepanek-uz commented 2 years ago

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.

miguel-arrf commented 1 year ago

I'm dealing with the same issue. Any update @phansen-nd ?

phansen-nd commented 1 year ago

@miguel-arrf no we ended up using a different network handler because this didn't work.

miguel-arrf commented 1 year ago

@miguel-arrf no we ended up using a different network handler because this didn't work.

Oh... @phansen-nd . Thank you anyway!

WestFlow127 commented 12 months ago

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?

WestFlow127 commented 11 months ago

@nuclearace can we get some input on this?

WestFlow127 commented 11 months ago

@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

neobie commented 5 months ago

It used to walk back in 2021. Not sure why now is not working when i am debugging.