Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket "disconnect" listener doesn't work when the server disconnects. #175

Open
Valeriegard opened this issue Feb 22, 2022 · 0 comments
Open

Comments

@Valeriegard
Copy link

So the desired behavior is that socket could get "disconnect" message from the server when the server app gets closed. It works with javascript apps but doesn't work with swift, can't get why. It changes status to "connection error" only after the ping timeout but not when the server disconnects.

All other listeners and connection itself work fine

var manager: SocketManager?
var socket: SocketIOClient?
var socketData = SocketIOData()


 func initializeSocketIO(ip:String, port: String, name: String) {
     
     socketData.stationName = name
     
     manager = SocketManager(socketURL: URL(string: "http://\(ip):\(port)")!, config: [.log(false)])
    
     socket = manager?.socket(forNamespace: "/")
     
 }
 func establishConnection(completionHandler: @escaping () -> Void) {

     socket?.connect(withPayload: socketData.items, timeoutAfter: 2) {
         completionHandler()
         print("Could not connect")
     }
 }

func statusListener() {

        //tried this, didn't work

        socket?.on("disconnect", callback: { (data, ack) in
            print("disconnect", data)
        })

       //this didn't work either
         socket?.on(clientEvent: .disconnect) {data, ack in
                debugPrint("socket disconnected")

            } 


            socket?.on(clientEvent: .error) {data, ack in
                debugPrint("socket error")
            }

            socket?.on(clientEvent: .reconnect) {data, ack in
                debugPrint("socket reconnecting")
            }

               

        socket?.on(clientEvent: .statusChange) {data, ack in
            debugPrint("STATUS CHAGE")

        }   
        
    }

What am I doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant