Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check socket.io connection status using swift API

I am using socket.io with my swift iOS app. Occasionally my socket connection is dropped.

How can I check the status of the connection so that I may re-connect if it is not connected? I couldn't find any commands for checking the status of the connection in the client API documents.

I'm using iOS 11 with swift 4.

like image 219
alionthego Avatar asked Dec 22 '25 14:12

alionthego


1 Answers

Swift 4:

    let socketConnectionStatus = socket.status

    switch socketConnectionStatus {
    case SocketIOStatus.connected:
        print("socket connected")
    case SocketIOStatus.connecting:
        print("socket connecting")
    case SocketIOStatus.disconnected:
        print("socket disconnected")
    case SocketIOStatus.notConnected:
        print("socket not connected")
    }
like image 91
John Bassos Avatar answered Dec 24 '25 04:12

John Bassos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!