Come posso eseguire il debug di chiamate TXJSON-RPC utilizzando un client JavaScript e Python Server?

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

  •  27-10-2019
  •  | 
  •  

Domanda

Ho implementato un'app WXPYTHON, che contiene anche un server TXJSONRPC contorto. Questo è il mio "server" RPC; Posso chiamarlo usando un socket TCP e i comandi di emissione.

Esiste uno script di test Python chiamato client_subhandled.py in txjsonrpc che ho usato per testare e chiama e riceve una risposta dal server RPC, quindi la comunicazione client/server Python funziona.

Tuttavia, devo effettuare chiamate JSON RPC da JavaScript, non da Python. Per fare ciò ho usato un piccolo applet Java che ti consente di aprire un socket TCP da JavaScript e leggere e scrivere da/da esso (java_socket_bridge.js). Funziona anche, l'ho testato non usando il protocollo JSON RPC, ma inviando e ricevo un testo semplice usando un semplice protocollo di eco contorto.

Il problema è che usando JavaScript come client, non riesco a far funzionare le chiamate RPC JSON. C'è un modo per eseguire il debug di chiamate JSON RPC in arrivo in TXJSONRPC? Idealmente mi piacerebbe vedere quali oggetti JSON entrano nel server per vedere se sono conformi.

Grazie!

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()
È stato utile?

Soluzione

hai provato a usare Wireshark ?

Fai attenzione, sembra che ci siano alcuni problemi quando si cattura su LocalHost;)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top