Am 20.06.2013 16:35, schrieb Kevin Campion:
> Hi,
>
> I am trying to get Autobahn.Python to work with disconnecting when
> server down, without having to restart the program. The client program
> must try to reconnect every x seconds to the server.
>
> My source code works but when client reconnects, I can see in server's
> log multiple connection for the same client. I have an
> additional connection per trying reconnection.
>
> I think, it's when I use "connector.connect()"
Yep, sounds a bit like you are piling up new clients which each tries
to reconnect again and again.
Probably instead of implementing a reconnection policy yourself (yes, we
are guilty of that also), we should use
http://twistedmatrix.com/documents/current/api/twisted.internet.protocol.ReconnectingClientFactory.html
http://twistedmatrix.com/documents/13.0.0/core/howto/clients.html
The "problem" is, Autobahn (currently) defines
class WebSocketClientFactory(protocol.ClientFactory, WebSocketFactory):
"""
A Twisted factory for WebSocket client protocols.
"""
protocol = WebSocketClientProtocol
==
Probably this works:
class MyFactory(ReconnectingClientFactory, WebSocketClientFactory)
Not sure, cannot test right now.
Possibly, the empty implementation in
WebSocketClientFactory.clientConnectionFailed and clientConnectionLost
are "in the way" ..
Anyway, I'd try to either use ReconnectingClientFactory or have a look
at the implementation.
/Tobias
>
> I use this discussion and the example on GitHub :
>
https://groups.google.com/forum/?fromgroups#!searchin/autobahnws/reconnect|sort:relevance/autobahnws/HCNFWKGYQCM/G1EGNGxOZXkJ
>
https://github.com/tavendo/AutobahnTestSuite/blob/master/autobahntestsuite/autobahntestsuite/testee.py#L87
> <
https://github.com/tavendo/AutobahnTestSuite/blob/master/autobahntestsuite/autobahntestsuite/testee.py#L87>
>
>
> My TesteeClientFactory class looks like this :
>
> class TesteeClientFactory(WebSocketClientFactory):
> protocol = TesteeClientProtocol
> def clientConnectionLost(self, connector, reason):
> connector.connect()
>
> def clientConnectionFailed(self, connector, reason):
> print "Connection to %s failed (%s)" % (self.url,
> reason.getErrorMessage())
> self.tryToConnect(connector)
> def tryToConnect(self, connector):
> connector.disconnect()
> var = 1
> while var == 1 :
> time.sleep( 2 )
> newConnection = connector.connect()
> if newConnection != None:
> break
> connector.disconnect()
>
> --
> 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.
> For more options, visit
https://groups.google.com/groups/opt_out.
>
>