Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

working with jsonrpclib #10

Open
sancelot opened this issue Oct 17, 2018 · 2 comments
Open

working with jsonrpclib #10

sancelot opened this issue Oct 17, 2018 · 2 comments

Comments

@sancelot
Copy link

I will have to connect to a server that uses https://github.com/joshmarshall/jsonrpclib api.

this is using http protocol.

My question may be silly from your viewpoint, but I need to know if it will work ?

Regards,
S.Ancelot

@nojvek
Copy link
Owner

nojvek commented Oct 27, 2018

You may have to implement the LikeSocket interface to connect using http protocol but it should work. Noice-rpc-json is a very thin layer that makes the json rpc interface look like making a function calls that return promises.

Sent with GitHawk

@sancelot
Copy link
Author

hi, I really do not understand howto implement a LikeSocket interface . I tried to implement my interface like this, but it has not worked :

import * as WebSocket from 'ws'
import * as rpc from 'noice-json-rpc'

interface example {
  getRandomInt(params: number) : Promise<number>;
 };

function getRandomInt(arg : number) : number { return arg ;}

async function setupClient() {
    try {
        const rpcClient = new rpc.Client(new WebSocket('ws://localhost:6002'), {logConsole: true})

        const api : example  = rpcClient.api()

        const result = await api.getRandomInt(10)

        console.log('Result', result)

    } catch (e) {
        console.error(e)
    }
}

setupClient()



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants