我做了一个像 SomeClient 这样的客户端,它与 WAMP v1 服务器通信。
正如您在第 25 行所见,我无法做的是从 HTTPServer 类调用 SomeClient.i_need_to_call_this 方法。
from twisted.internet import reactor
from twisted.web import server, resource
from autobahn.wamp1.protocol import WampClientFactory, WampCraClientProtocol
from autobahn.twisted.websocket import connectWS
class SomeClient(WampCraClientProtocol):
def __init__(self):
pass
def doSomething(self, something):
return something
def i_need_to_call_this(self):
d = self.call("http://somewhere")
d.addCallback(self.doSomething)
class HTTPServer(resource.Resource):
isLeaf = True
def render_GET(self, request):
request.setHeader("content-type", "application/json")
result = "Here i need to call SomeClient.i_need_to_call_this and render the result"
return result
if __name__ == '__main__':
factory = WampClientFactory("wss://someurl")
factory.protocol = SomeClient
connectWS(factory)
reactor.listenTCP(8080, server.Site(HTTPServer()))
reactor.run()