How can I debug txJSON-Rpc calls using a javascript client and Python server?

StackOverflow https://stackoverflow.com/questions/8838334

  •  27-10-2019
  •  | 
  •  

سؤال

I have implemented a wxPython app, that also has a Twisted txJSONrpc server in it. This is my RPC "server"; I can call it using a TCP socket and issue commands.

There is a Python test script called client_subhandled.py in txjsonrpc that I used to test, and it calls and receives an answer from the RPC server, so Python client/server communication works.

However, I need to make JSON RPC calls from javascript, not from Python. To do that I have used a small java applet that allows you to open a TCP socket from javascript and read and write to/from it (java_socket_bridge.js). This also works, I have tested it not using the JSON RPC protocol, but sending and receiving plain text using a simple twisted echo protocol.

The problem is that using javascript as a client, I can't seem to get rpc JSON calls to work. Is there a way to debug incoming JSON rpc calls in txJSONrpc? I would ideally like to see what JSON objects come in in the server to see if they're compliant.

Thanks!

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()
هل كانت مفيدة؟

المحلول

have you tried using Wireshark ?

Be careful, it seems like there are some issues when capturing on localhost ;)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top