我已经离开了我的舒适区,我有点困惑我该怎么登录。
Autobahn提供了一种使用RPC调用Python服务器的方法,但是Twisted只提供了如何为客户机使用Twisted的文档。
为了正确解释我的意思,下面是代码:
在Javascript中,可以像这样调用RPC函数:
sess.call(url, user, pass)
Python客户端代码:
from twisted.spread import pb
from twisted.internet import reactor
from twisted.cred import credentials
class Client(pb.Referenceable):
def remote_print(self, message):
print message
def connect(self):
factory = pb.PBClientFactory()
reactor.connectTCP("localhost", 8800, factory)
def1 = factory.login(credentials.UsernamePassword("Bob", "secret"),
client=self)
def1.addCallback(self.connected)
reactor.run()
def connected(self, perspective):
self.perspective = perspective
d = perspective.callRemote("joinGroup", "#Magic")
d.addCallback(self.gotGroup)
def gotGroup(self, group):
d = group.callRemote("send", "Test message.")
d.addCallback(self.shutdown)
def shutdown(self, result):
reactor.stop()
Client().connect()
Python服务器代码:
^{pr2}$基本上,我只需要找出如何通过RPC在Javascript中访问登录调用,但我不知道如何做到这一点,Google也没有为我提供任何选项。
Autobahn project不仅提供WebSocket的实现(其中之一是AutobahnPython),而且还提供WAMP (The WebSocket Application Messaging Protocol):
WAMP同样得到了AutobahnPython和AutobahnJS(以及越来越多的其他实现。。见here)。似乎带有高速公路的高速公路可以让你做你想做的事情:
免责声明:我是《高速公路和WAMP》的原作者,为塔文多工作。在
在高速公路站点和相应的GitHub repo中有RPC和PubSub的多个完整的工作示例,例如here。在
相关问题 更多 >
编程相关推荐