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

32600 - Invalid request #83

Closed
raskyer opened this issue Jan 6, 2017 · 5 comments
Closed

32600 - Invalid request #83

raskyer opened this issue Jan 6, 2017 · 5 comments

Comments

@raskyer
Copy link

raskyer commented Jan 6, 2017

Hello,

First, thanks for your wonderfull work.

I'm trying to have a both communication point from Golang (client - serv) and Node (with your lib) (client serv)

When I try from my program in Go to call 127.0.0.1 3000 (because I'm running the node server on local). I got the following message 👍

[{"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"Invalid request"}},{"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"Invalid request"}}]

Have you any doc that could allow me to bind a valid request because for now I just send to the server (in json) an array of int like =>

[10, 10]

The server code =>

// create a server
var server = jayson.server({
  add: function(args, callback) {
    callback(null, args[0] + args[1]);
  }
});

server.tcp().listen(3000);

Client code in go =>

var reply int
conn, err := net.Dial("tcp", r.Client[0].Addr)

if err != nil {
	fmt.Println(err)
	return
}

defer conn.Close()

c := jsonrpc.NewClient(conn)
err = c.Call("add", []int{10, 10}, &reply)

if err != nil {
	fmt.Println(err)
	return
}
	
fmt.Printf("Add: %d", reply)

Thank you :)

@raskyer
Copy link
Author

raskyer commented Jan 6, 2017

I found out what should I specify in my request like =

{"jsonrpc":"2.0", "method":"add", "params":[10,10]}

But now I got an other problem. (I try using telnet). When I send this with telnet I can't have an answer from the server (basically 10 + 10 result in this example). But callback seem to be a valid function when I console.log it...

@raskyer
Copy link
Author

raskyer commented Jan 6, 2017

Okay really sorry @tedeh I'm starting to understand.

On the server/index.js we got those lines =>

 var respond = function(error, result) {
      if(utils.Request.isNotification(request)) return callback();
      var response = utils.response(error, result, request.id, self.options.version);
      if(response.error) callback(response);
      else callback(null, response);
    };

It seems that when I call the server with the former parameter I mention, the first if is activate =>

 if(utils.Request.isNotification(request)) return callback();

Because callback() has no argument it's an undefined response sent. If I comment this line. Everything seems fine and I got the excepted answer :

{"jsonrpc":"2.0","id":null,"result":20}

@raskyer
Copy link
Author

raskyer commented Jan 6, 2017

Ok I understand it by looking at utils.isNotification, I need an "id" to get the answer.
Thanks !

@raskyer raskyer closed this as completed Jan 6, 2017
@tedeh
Copy link
Owner

tedeh commented Jan 7, 2017

He he, yes, you need an ID or your request is considered a notification, which means that it does not expect a response.

@Juan-Bustamante
Copy link

Thanks for all these questions and answers. Saved me a lot of time!

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

3 participants