You can download this code by clicking the button below.
This code is now available for download.
This function creates a WebSocket server based on the Autobahn library, which accepts two arguments and calls the remote Procedure 'com.myapp.add' with these arguments when a connection is established.
Technology Stack : Autobahn, Twisted
Code Type : Websocket Server Application
Code Difficulty : Intermediate
from autobahn.wamp import Application, ApplicationSession, Component
from twisted.internet.endpoints import TCP4ServerEndpoint
from twisted.internet import reactor
def xxx(arg1, arg2):
class MyComponent(Component):
def on_join(self, details):
print("Connected to router")
self.session.call("com.myapp.add", arg1, arg2)
app = Application(MyComponent)
endpoint = TCP4ServerEndpoint(reactor, 8123)
reactor.listenTCP(8123, endpoint, factory=app)
reactor.run()