Coder Social home page Coder Social logo

Comments (15)

tomusdrw avatar tomusdrw commented on July 20, 2024

If you have a running server from this example:
https://github.com/paritytech/jsonrpc/blob/a95e135017c3a29fbda5dad88dc62f8797792443/pubsub/examples/pubsub.rs

You need to issue a standard RPC with {"id":1,"jsonrpc":"2.0","method":"subscribe_hello"} and then you should start seeing subscriptions coming to your client.
The transport used in the example is TCP, so you can for instance use netcat to connect to the server:

$ netcat localhost 3030 -
{"id":1,"jsonrpc":"2.0","method":"subscribe_hello"}
{"jsonrpc":"2.0","result":5,"id":1}
{"jsonrpc":"2.0","method":"hello","params":[10]}
{"jsonrpc":"2.0","method":"hello","params":[10]}
{"jsonrpc":"2.0","method":"hello","params":[10]}

from jsonrpc.

faern avatar faern commented on July 20, 2024

I'm running the example using macros at https://github.com/paritytech/jsonrpc/blob/a95e135017c3a29fbda5dad88dc62f8797792443/macros/examples/pubsub-macros.rs

But I get this:

$ netcat localhost 3030 -
{"id":1,"jsonrpc":"2.0","method":"hello_subscribe"}
{"jsonrpc":"2.0","error":{"code":-32601,"message":"Method not found"},"id":1}

from jsonrpc.

faern avatar faern commented on July 20, 2024

I did get your example to work with the example not using macros. But using the macros would be sweet.

from jsonrpc.

tomusdrw avatar tomusdrw commented on July 20, 2024

Hmm, you're right. It turned out that the alias invocation in macros was invalid (it was overriding the implementation with alias to non-existent method).

Please try with #121 or remove alias in the example.

from jsonrpc.

faern avatar faern commented on July 20, 2024

That worked better! Thanks. Now I get:

$ netcat localhost 3030 -
{"id":1,"jsonrpc":"2.0","method":"hello_subscribe","params":[10]}
{"jsonrpc":"2.0","result":0,"id":1}
{"jsonrpc":"2.0","method":"hello","params":{"result":"Hello World!","subscription":0}}
{"jsonrpc":"2.0","method":"hello","params":{"result":"Hello World!","subscription":0}}
{"jsonrpc":"2.0","method":"hello","params":{"result":"Hello World!","subscription":0}}
....

Now I will just move on to try to get this running on the WebSocket server.

from jsonrpc.

tomusdrw avatar tomusdrw commented on July 20, 2024

You can have a look how we wrapped the ws::Sender into mpsc::Sender:
https://github.com/paritytech/parity/pull/5456/files#diff-047350db0c9925ab2d582dfcd955f0a4R173

I'm considering moving this into this crate though.
If you manage to get the example running feel free to contribue it to ws/examples :)

from jsonrpc.

faern avatar faern commented on July 20, 2024

I got the server running. But when I try to communicate with in using a python websocket client I get this response:

{"jsonrpc":"2.0","error":{"code":-32090,"message":"Subscriptions are not available on this transport."},"id":1}

Is there anything I can do about that? Would the ws crate need some modifications or which part is it that stops subscriptions to work over ws?

from jsonrpc.

tomusdrw avatar tomusdrw commented on July 20, 2024

Could you post the example somewhere? For PubSub to work you need to ensure that MetadataExtractor will create a Session object (that definitely needs more detailed documentation).

from jsonrpc.

faern avatar faern commented on July 20, 2024

Ah. My bad. I removed the call to session_meta_extractor. Now I'm trying to figure out how to make that work. Looking at the code you sent, but it uses rpc::PubSubSession which is not part of this repository.

from jsonrpc.

faern avatar faern commented on July 20, 2024

It kind of escalates with the WsRpcExtractor and the Sender struct implementing Future etc. There is hopefully a simpler way that I have not found yet.

from jsonrpc.

tomusdrw avatar tomusdrw commented on July 20, 2024

It's actually just a re-export of jsonrpc_pubsub::Session. I'll prepare an example today for you :)

from jsonrpc.

faern avatar faern commented on July 20, 2024

Thank you. That would be awesome.

from jsonrpc.

tomusdrw avatar tomusdrw commented on July 20, 2024

Please have a look at #126. I've moved the implementation of mpsc::Sender to this crate.

from jsonrpc.

faern avatar faern commented on July 20, 2024

@tomusdrw Thanks for the help! Got it working and also got an example based on macros working. Merging that PR would solve/close this issue.

from jsonrpc.

tomusdrw avatar tomusdrw commented on July 20, 2024

Awesome! Glad to hear that.

from jsonrpc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.