2012-01-12 106 views
0

我已經實現了一個wxPython應用程序,它裏面還有一個Twisted txJSONrpc服務器。這是我的RPC「服務器」;我可以使用TCP套接字調用它併發出命令。如何使用JavaScript客戶端和Python服務器調試txJSON-Rpc調用?

在我用於測試的txjsonrpc中有一個名爲client_subhandled.py的Python測試腳本,它調用並接收來自RPC服務器的答案,以便Python客戶端/服務器通信起作用。

但是,我需要從JavaScript,而不是從Python進行JSON RPC調用。爲此,我使用了一個小型java小程序,它允許您從javascript打開一個TCP套接字並讀寫它(java_socket_bridge.js)。這也適用,我測試過它不使用JSON RPC協議,但使用簡單的扭曲回聲協議發送和接收純文本。

問題是,使用JavaScript作爲客戶端,我似乎無法獲得rpc JSON調用工作。有沒有辦法在txJSONrpc中調試傳入的JSON rpc調用?我希望看到服務器中有哪些JSON對象進入,以查看它們是否符合要求。

謝謝!

from twisted.internet import wxreactor # socket library 
wxreactor.install()      # for using twisted along with wxPython 

# using netstring TCP protocol 
from txjsonrpc.netstring import jsonrpc 
from twisted.web import server 

# import twisted reactor *only after* installing wxreactor 
from twisted.internet import reactor 

myreactor = reactor 

def register(application): 
    # initialise and run the TWISTED reactor 
    reactor.registerWxApp(application) 
    #rpcCom.myreactor.listenTCP(9000, rpcCom.EchoServerFactory()) 
    reactor.listenTCP(9000, factory) 
    reactor.run() 

class Example(jsonrpc.JSONRPC): 
    """An example object to be published.""" 

    def jsonrpc_echo(self, x): 
     """Return all passed args.""" 
     print "echo called" 
     return x 

class Testing(jsonrpc.JSONRPC): 

    def jsonrpc_getList(self): 
     """Return a list.""" 
     return [1,2,3,4,'a','b','c','d'] 

class Math(jsonrpc.JSONRPC): 
    """ 
    An example object to be published. 
    """ 
    def jsonrpc_add(self, a, b): 
     """ 
     Return sum of arguments. 
     """ 
     return a + b 

factory = jsonrpc.RPCFactory(Example) 
factory.putSubHandler('math', Math) 
factory.putSubHandler('testing', Testing) 

factory.addIntrospection() 
+0

[Wireshark的(https://www.wireshark.org/) – yanjost 2012-01-12 16:22:09

+0

喜@yanjost,我已經安裝了Wireshark的,但它無法在同一臺計算機上捕獲客戶端服務器流量:http://wiki.wireshark.org/CaptureSetup/Loopback – 2012-01-13 13:25:30

+0

您是否嘗試過此頁面上的不同配方,作爲回送問題的解決方法? – yanjost 2012-01-13 14:14:28

回答

0

您是否嘗試過使用Wireshark

小心,好像有一些捕捉本地主機上,當問題;)

相關問題