nuclearace / Socket.IO-Client-Swift

socket.io-client for Swift
Other
361 stars 53 forks source link

My ReachabilityStatus changed but socket is not disconnect #131

Closed GloamZz closed 8 years ago

GloamZz commented 8 years ago

I use AFNetworking to monitor the network status. Let's start it following the steps.

_The socket.io won't be disconnected!_ _It means that my socket is still connected with the IP and port of WWAN. (Or you do something like reconnecting in the background for a new IP and port.)_

But if my networking status changed from WiFi to WWAN. The socket will be disconnected and the error "未能完成该操作。Socket is not connected," is called.

Although there is no problem about the disconnecting from WiFi to WWAN, I invoke reconnect for socket.io, and nothing happens. (I set NO for the option "reconnects", because I want to receive the disconnected message immediately when the socket is disconnected. )

Can you introduce the reconnecting system for me? I work with Objective-C and it's hard for me to read Swift code. What's the difference between "reconnects" and "reconnectAttempt"? I found it will always be called at the same time. And if I want to do the reconnecting by myself, what else should I do besides setting the reconnects with NO? Should I clean the socket, and create a new socket to connect? I think you will do these via the reconnect method.

nuclearace commented 8 years ago

I thought I already answered this on the main repo?

reconnect - Fired once when the socket is disconnected and it can reconnect reconnectAttempt - Fired each time the socket tries to reconnect disconnect - Fired when the socket has disconnected and cannot reconnect or has reached the max number of reconnect attempts.

If you want to to do the reconnecting yourself you can set .Reconnects(false) and listen for the disconnect. I would then recommend readding the socket. That way you know for sure that any previous state stuff is gone. (I haven't tested calling connect on a closed socket as thoroughly)