def call(self, *args): """ Perform a remote-procedure call (RPC). The first argument is the procedure URI (mandatory). Subsequent positional arguments can be provided (must be JSON serializable). The return value is a Twisted Deferred. """ if len(args) < 1: raise Exception("missing procedure URI") if type(args[0]) not in [unicode, str]: raise Exception("invalid type for procedure URI") procuri = args[0] while True: callid = newid() if not self.calls.has_key(callid): break d = Deferred() self.calls[callid] = d msg = [WampProtocol.MESSAGE_TYPEID_CALL, callid, procuri] msg.extend(args[1:]) try: o = json.dumps(msg) except: raise Exception("call argument(s) not JSON serializable") self.sendMessage(o) return d
def onOpen(self): """ Default implementation for WAMP connection opened sends Welcome message containing session ID. """ self.session_id = newid() msg = [WampProtocol.MESSAGE_TYPEID_WELCOME, self.session_id] o = json.dumps(msg) self.sendMessage(o) self.factory._addSession(self, self.session_id) self.onSessionOpen()
def onOpen(self): """ Default implementation for WAMP connection opened sends Welcome message containing session ID. """ self.session_id = newid() msg = [ WampProtocol.MESSAGE_TYPEID_WELCOME, self.session_id, WampProtocol.WAMP_PROTOCOL_VERSION, "Autobahn/%s" % autobahn.version, ] o = json.dumps(msg) self.sendMessage(o) self.factory._addSession(self, self.session_id) self.onSessionOpen()