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

Unable to reconnect #207

Closed
motoom opened this issue Jan 26, 2017 · 4 comments
Closed

Unable to reconnect #207

motoom opened this issue Jan 26, 2017 · 4 comments

Comments

@motoom
Copy link

motoom commented Jan 26, 2017

I run a chat service with CherryPy and ws4py. The client runs in a webbrowser and is very similar to the chat example from ws4py. When the client notices that the connection has been disconnected (this can happen easily, for example, due to an unstable Wifi connection), I try to re-establish the connection to the server. This somehow doesn't work. Am I trying to do something that is unsupported, or should it indeed be possible to reconnect a closed-down websocket? In the first case, I must find an alternative to ws4py, in the second case, I can prepare a minimal code example which demonstrates the behaviour.

@adippel
Copy link

adippel commented Feb 8, 2017

I faced the same task recently. AFAIK, ws4py does not provide a reconnect functionality. You have to implement it on your own by subclassing. However, simply calling connect() again might throw some errors especially when using encrypted connections. You have to make sure, that the previous connection is closed completely on the client-side before trying to call connect() again.
Have a look at this example I found: https://github.com/belisarius222/ws4py-reconnect/blob/master/wsclient.py

@EternityForest
Copy link
Contributor

Is this related at all to issue #150 where an abrupt disconnection will crash the server?

@adippel
Copy link

adippel commented Mar 24, 2017

AFAICS, your issue relates to problems on the server side. This issue, though, deals with a reconnection logic on the client side.
I referred to an example in my lost post. However, it seems like this example leads to a memory leak since it instantiates a new object on every reconnection try.
The threaded client is hard to extend since a lot of setup and priming is done in the underlying constructors. I came up with a solution without creation of a new instance on every reconnect try. The solution is working okish but is rather hacky as it tries to mimic the setup and priming in the Subclasses of the threaded client.
You can find my minimal working example here: https://gist.github.com/adippel/a417d95d8401c09c158bac3c7ba92f07

@tito
Copy link
Contributor

tito commented Mar 24, 2017

Duplicate of #150
This has been fixed in master, and will be released soon.

@tito tito closed this as completed Mar 24, 2017
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

4 participants