socketio / socket.io-client-swift

Other
5.21k stars 841 forks source link

Connection took too much time on low bandwidth internet #1440

Open MuhammadAhmedBaig opened 1 year ago

MuhammadAhmedBaig commented 1 year ago

In our application, we are using a socket for the core feature of our application, and we need to make sure that the socket is connected to low-bandwidth internet as well. So, I make my network speed Edge (from Network Conditioner in the Developer Mode option on iPhone). Now, I am receiving approx 230 to 250Kpbs speed on my device. Now, when I tried to connect the socket in this condition it took sometimes 5 seconds even sometimes 10 seconds. Here is my connection code.

public func connect() {
    if socket == nil {
        socket = self.manager.socket(forNamespace: CallSocketHandlerConstants.nameSpace.rawValue)
        self.observeSocketMsgEvents()
        self.observeSocketClientEvents()
    }
    if socket?.status != .connected || socket?.status != .connecting {
        socket?.connect()
    }
}

And the reconnection code:

@objc public func reconnect(isForced: Bool = false) {
    if self.isReconnecting && !isForced { return }
    self.isReconnecting = true
    socket?.disconnect()
    manager.disconnect()
    socket?.connect()
}

Also, we are facing some weird issues, sometimes socket layer got disconnected but the socket manager is connected internally and vice vera.

Any solutions?