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

Reconnect #415

Closed
blajivskiy opened this issue Oct 27, 2017 · 6 comments
Closed

Reconnect #415

blajivskiy opened this issue Oct 27, 2017 · 6 comments

Comments

@blajivskiy
Copy link

Hey. Tell me please, can I do reconnect this way:

socket.onDisconnect = { (error: error?) in {
self.socket.connect ()
}

At such attempt I have errors in the console and when I call connect () I do not get into onDisconnect {} any more. :( The main thing is that on swift 3 this method worked.

I ask you to give advice on how to improve my code. Thank you in advance for your cooperation.

@blajivskiy
Copy link
Author

It seems to me that I understood the essence of the problem:

If there is no internet connection and we send a request via webSocket, we do not receive any notifications. Also, if a request was sent without the Internet to the server (1), then another, separate object will not send a request to the server (2), because it will be occupied by the server (1). I tried on different threads and nothing happens: (

@blajivskiy
Copy link
Author

I rolled back to version 2.1.1 and everything works fine. Please correct in the new update.

@daltoniam
Copy link
Owner

I'm not sure what you are seeing and thus I can't correct it. There have been a lot of changes from 2.1.1 to the latest version, but all the versions have passed the Autobahn tests as expected. onDisconnect still works in all of my tests, so I would appreciate a sample project or some code to reproduce the problem with.

@blajivskiy
Copy link
Author

The code is simple:

socket.onDisconnect = {[weak self] (error: error?) in {
self? .socket.connect ()
}

In version 2.1.1, when calling self.socket.connect () in the socket.onDisconnect = {block: error?} In {}, if there is no connection, the socket.onDisconnect = {is returned again. {{Error: error?} { }, as in the example above. It works cyclically as it should work.

In versions> 3 block socket.onDisconnect = {(error: error?) In {} it is called once, despite the fact that it contains self.socket.connect () and there is no connection to the server. And if a code call is higher and a connection is made to another socket on another server, then the other connector will not connect. It seems that the first socket does not do this and the second one can not complete the connection.

@daltoniam
Copy link
Owner

I did a bit of digging in this. The issue is the underlining socket isn't ready for reuse when you call connect again. The foundation stream object never becomes "ready" (hasSpaceAvaliable is never updated to true). This create a cycle of attempting to reconnect and the socket never being ready. I generally would avoid calling connect() straight from a disconnect call, as you normally would to check a few things to see if the socket isn't actually disconnected. Regradless, you can just add a bit of delay and all will work fine again (just use DispatchQueue.main.AsyncAfter(deadline: .now() + 0.5,{socket.connect()}).

P.S. 3.0.4 was also just released with some better disconnect logic.

@parski
Copy link

parski commented Feb 5, 2018

as you normally would to check a few things to see if the socket isn't actually disconnected

What things should we check before calling connect()? Is the proper way to solve this in the host implementation or should this be fixed in Starscream?

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

3 participants