--- a/runtime/WampClient.py Wed Apr 18 10:40:16 2018 +0200
+++ b/runtime/WampClient.py Wed Apr 18 10:42:33 2018 +0200
@@ -27,6 +27,7 @@
from autobahn.twisted import wamp
from autobahn.twisted.websocket import WampWebSocketClientFactory, connectWS
from autobahn.wamp import types, auth
@@ -35,6 +36,7 @@
from twisted.internet.protocol import ReconnectingClientFactory
+_transportFactory = None @@ -132,13 +134,16 @@
print(_('WAMP session joined (%s) by:' % time.ctime()), ID)
def onLeave(self, details):
+ global _WampSession, _transportFactory + super(WampSession, self).onLeave(details) + _transportFactory = None print(_('WAMP session left'))
class ReconnectingWampWebSocketClientFactory(WampWebSocketClientFactory, ReconnectingClientFactory):
def __init__(self, config, *args, **kwargs):
+ global _transportFactory WampWebSocketClientFactory.__init__(self, *args, **kwargs)
protocolOptions = config.extra.get('protocolOptions', None)
@@ -148,18 +153,25 @@
self.setProtocolOptions(**validProtocolOptions)
#print(_("Added custom protocol options"))
+ _transportFactory = self def buildProtocol(self, addr):
return ReconnectingClientFactory.buildProtocol(self, addr)
def clientConnectionFailed(self, connector, reason):
- print(_("WAMP Client connection failed (%s) .. retrying .." % time.ctime()))
- ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
+ if self.continueTrying: + print(_("WAMP Client connection failed (%s) .. retrying .." % time.ctime())) + super(ReconnectingWampWebSocketClientFactory, self).clientConnectionFailed(connector, reason) def clientConnectionLost(self, connector, reason):
- print(_("WAMP Client connection lost (%s) .. retrying .." % time.ctime()))
- ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
+ if self.continueTrying: + print(_("WAMP Client connection lost (%s) .. retrying .." % time.ctime())) + super(ReconnectingWampWebSocketClientFactory, self).clientConnectionFailed(connector, reason) def LoadWampClientConf(wampconf):
@@ -184,13 +196,23 @@
+ if re.match(r'w{1}s{1,2}:{1}/{2}.+:{1}[0-9]+/{1}.+', uri): def RegisterWampClient(wampconf, secretfname):
WSClientConf = LoadWampClientConf(wampconf)
print(_("WAMP client connection not established!"))
+ if not IsCorrectUri(WSClientConf["url"]): + print(_("WAMP url {} is not correct!".format(WSClientConf["url"]))) WampSecret = LoadWampSecret(secretfname)
@@ -215,10 +237,16 @@
# start the client from a Twisted endpoint
conn = connectWS(transport_factory)
print(_("WAMP client connecting to :"), WSClientConf["url"])
+def GetTransportFactory(): + global _transportFactory + return _transportFactory