Description
Hi there.
I'm setting up a public server to test an RPC call from anywhere, but when it comes to call an RPC function it returns:
{ code: -32601, message: 'Method not found' }
It's pretty weird because I tested the rpc method with wscat like so:
- Connected to the rpc server with: wscat --connect ws://localhost:8082
- Once connected, I used this cmd to call the 'test' method.
{"jsonrpc": "2.0", "method": "/test", "params": null, "id": 1}
and as you can see in the following image, it returns as expected:
But when I try to call the same method with rpc-websockets client library it just returns { code: -32601, message: 'Method not found' }
This is my current setup on both client and server:
Client
RPC.on('open', async function() {
console.log("Client connected [OK]");
const meths = await RPC.listMethods();
console.log(meths);
try {
const result = await RPC.call('/test', null);
console.log(result);
}
catch(err) {
console.log(err);
}
});
RPC.on('error', function(err) {
console.log(err);
});
And this is the Output that I get from my terminal on Client:
As you can see, I make a call to listMethods, but no methods are registered, so IDK why that happens. But I'm able to perform a call to the method itself with wscat tool.
Server
const WebSocketServer = require('rpc-websockets').Server;
const rpc = new WebSocketServer({
port: '8082',
host: 'localhost'
});
rpc.register('/test', params => {
console.log("Test RPC [OK]");
console.log(params);
return 'OK RET';
});
I'm really stuck with this issue and I'm not able to resolve it.
It would be great if you could help me to figure out what's going on.
I'll really appreciate it. Thank you very much in advance.