I am new to autobahn and just joined this group.
I am kind of new to Python too so please forgive my mistakes.
I’d like to implement websockets in an application but I am kind of stuck at the moment.
I would like to call protocol methods, such as sending a specific message, from another module.
Not complicated, well maybe, here is how my application works :
A process is running outside the protocol module and is supposed to retrieve the protocol instance every X period in order to see if a connection has opened.
When a user opens a connection, it fires the onOpen() functions, which sets the value of the attribute isRunning of the protocol instance to True.
As long as the isRunning attribute of the protocol instance is set to True, the process fires a specific function of the protocol and sends a message.
The Protocol inherits from WebSocketServerProtocol and when it’s initiated sets the value of isRunning to False.
So I used the Singleton pattern with a decorator for the protocol in order to retrieve the right instance from the other module.
But, when a connection is opened, the value of the attribute is set once to True (in onOpen() ) but then is immediatly reseted to False.
Somehow i think it’s because when it retrieves the protocol instance, its method init which sets the attribute again to False is called.
How come ? Should i use Borg Pattern in order to set correctly the attribute ?
Thanks a lot for your great work on Autobahn !
Here is the code of the protocol :
instance = cls()
instance.call = lambda: instance
def init(self) :
self.isRunning = False
self.isRunning = True
print “new connection”
And Here is how i retrieve the protocol in the other module.
I am using this function every X secs:
server = ServerProtocol()
if server.isRunning :