Asyncio reconnecting on disconnect

#1

I’m trying to write a websocket client that is able to reconnect to the server when it loses connection.

I see there is an example for reconnecting when using twisted at:
https://github.com/tavendo/AutobahnPython/blob/master/examples/twisted/websocket/echo_variants/client_reconnecting.py

What would be the correct way to implement this when using Asyncio?

0 Likes

#2

I'm trying to write a websocket client that is able to reconnect to the
server when it loses connection.

I see there is an example for reconnecting when using twisted at:
https://github.com/tavendo/AutobahnPython/blob/master/examples/twisted/websocket/echo_variants/client_reconnecting.py

What would be the correct way to implement this when using Asyncio?

Well, one way would be: implement something like: upon connection loss, sleep some time (possibly with exponential backoff) and then try to connect (once). loop until connected. reset backoff upon connect.

something in this direction:

https://code.google.com/p/tulip/source/browse/examples/cacheclt.py#104

this might of interest too:

https://groups.google.com/forum/#!topic/python-tulip/9lIABK73zAc
http://twistedmatrix.com/trac/ticket/4735

hope this helps,

/Tobias

···

Am 29.06.2014 03:53, schrieb Darkman802:

--
You received this message because you are subscribed to the Google
Groups "Autobahn" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to autobahnws+...@googlegroups.com
<mailto:autobahnws+...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.

0 Likes

#3

Thank you for the resources, sadly it seems most of the underpinnings of asyncio are a bit over my head right now.

I understand the general logic behind line 104 in cacheclt.py, but not where I would implement it, for example, in the websocket echo client example.
I’m also not sure what other changes I would need to make (if any) due to the fact that it’s a coroutine.

So far I’ve only got this solution that remakes the factory and connection if it gets the onClose event.

http://pastebin.com/iLxBtm5S

···

On Saturday, June 28, 2014 10:15:52 PM UTC-4, Tobias Oberstein wrote:

Am 29.06.2014 03:53, schrieb Darkman802:

I’m trying to write a websocket client that is able to reconnect to the

server when it loses connection.

I see there is an example for reconnecting when using twisted at:

https://github.com/tavendo/AutobahnPython/blob/master/examples/twisted/websocket/echo_variants/client_reconnecting.py

What would be the correct way to implement this when using Asyncio?

Well, one way would be: implement something like: upon connection loss,
sleep some time (possibly with exponential backoff) and then try to
connect (once). loop until connected. reset backoff upon connect.

something in this direction:

https://code.google.com/p/tulip/source/browse/examples/cacheclt.py#104

this might of interest too:

https://groups.google.com/forum/#!topic/python-tulip/9lIABK73zAc

http://twistedmatrix.com/trac/ticket/4735

hope this helps,

/Tobias

0 Likes