Comment puis-je déboguer les appels txJSON-Rpc à l'aide d'un client javascript et le serveur Python?

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

  •  27-10-2019
  •  | 
  •  

Question

Je l'ai mis en place une application wxPython, qui a également un serveur Twisted txJSONrpc en elle. Ceci est mon RPC « serveur »; Je peux l'appeler à l'aide d'un socket TCP et exécuter des commandes.

Il y a un script de test Python appelé client_subhandled.py en txjsonrpc que je l'habitude de test, et il appelle et reçoit une réponse du serveur RPC, si la communication fonctionne client Python / serveur.

Cependant, je dois faire des appels RPC JSON de javascript, pas de Python. Pour ce faire, je l'ai utilisé une petite applet java qui vous permet d'ouvrir une socket TCP de javascript et lire et écrire / de celui-ci (java_socket_bridge.js). Cela fonctionne aussi, je l'ai testé pas en utilisant le protocole RPC JSON, mais envoyer et recevoir le texte brut en utilisant un protocole simple écho tordu.

Le problème est que l'utilisation de javascript en tant que client, je ne peux pas sembler recevoir des appels rpc JSON au travail. Est-il possible de déboguer les appels entrants JSON rpc à txJSONrpc? Idéalement je voudrais voir ce que les objets JSON viennent dans le serveur pour voir si elles sont conformes.

Merci!

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()
Était-ce utile?

La solution

avez-vous essayé d'utiliser Wireshark ?

Attention, il semble qu'il y ait des problèmes lors de la capture sur localhost;)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top