#2486 Modified reconnect function. Added 'active' parameter to wampconf.json file.
--- a/runtime/WampClient.py Thu Apr 19 13:40:56 2018 +0200
+++ b/runtime/WampClient.py Wed May 09 09:59:53 2018 +0200
@@ -26,6 +26,7 @@
from __future__ import print_function
import time
import json
+import os
import inspect
import re
from autobahn.twisted import wamp
@@ -207,9 +208,10 @@
return WSClientConf
except ValueError, ve:
- print(_("WAMP load error: "), ve)
- return None
- except Exception:
+ print(_("WAMP save error: "), ve)
+ return None
+ except Exception, e:
+ print(_("WAMP save error: "), e)
return None
def LoadWampSecret(secretfname):
@@ -272,24 +274,33 @@
print(_("WAMP client connecting to :"), WSClientConf["url"])
return True # conn
-
-def ReconnectWampClient(active, url):
- SaveWampClientConf(_WampConf, url, active)
-
- if not active and _WampSession:
- # crossbar connection active is off, retry connection off
- _transportFactory.stopTrying()
- return _WampSession.leave()
- elif _WampSession and active:
- # do reconnecting
+def StopReconnectWampClient():
+ _transportFactory.stopTrying()
+ return _WampSession.leave()
+
+def StartReconnectWampClient():
+ if _WampSession:
+ # do reconnect
_WampSession.disconnect()
return True
- elif not _WampSession and active:
- # crossbar connection active is on, do connect
+ elif not _WampSession:
+ # do connect
RegisterWampClient()
return True
- else:
- return False
+
+def ReconnectionWampClient(active, url):
+ """ReconnectionWampClient function used for reconnecting to Crossbar router.
+
+ Args:
+ active (bool): Value in wampconf.json file. True: using Wamp connection. False: not using Wamp connection.
+ url (str): Value in wampconf.json file. Url of Crossbar router.
+ """
+ SaveWampClientConf(_WampConf, url, active)
+
+ if active:
+ StartReconnectWampClient()
+ elif not active and _WampSession:
+ StopReconnectWampClient()
def GetSession():
return _WampSession
--- a/tests/wamp/project_files/wampconf.json Thu Apr 19 13:40:56 2018 +0200
+++ b/tests/wamp/project_files/wampconf.json Wed May 09 09:59:53 2018 +0200
@@ -1,4 +1,5 @@
{
+ "active": true,
"url":"ws://127.0.0.1:8888",
"realm":"Automation",
"ID":"wamptest",