Reputation: 933
I use Starscream. How can I check the socket is connecting or not?
isConnecting
is a private property.
Upvotes: 1
Views: 2460
Reputation: 257
In case if you want to check your socket is still alive (In case if you feel that it might be dead for example you are not receiving a packets stream you are suppose to get) then you can send ping, it will result in triggering websocketDidDisconnect method in case socket is gone. and Yes, You are right isConnected says that it was connected in the past so you can not rely on it.
func sendPing() {
guard let socket = socket, socket.isConnected
else { return }
socket.write(ping: "PING")
}
Upvotes: 0
Reputation: 58129
You should use socket.isConnected
:
if socket.isConnected {
//socket is connected
}
Upvotes: 1