Client creation for RPC call

Hi,

I am trying to call an RPC function from the client side. I am making all the function calls with a client created over an IP and a port number that is 7350.

I understand from the docs that I need to make the RPC calls from another port that is 7349. Do i have to create a new client with that parameters? And is it possible to use the session created through the authentication made via the client working on 7350 port?

I couldn’t make an RPC call trying all those possibilities, I ll appreciate if you help me

Thanks.

This is not the case. Port 7349 is where you can reach Nakama’s GRPC listener, and port 7350 is the HTTP listener. Both can perform all functions available in Nakama - the distinction is the transport layer, not features.

Could you point out where in the docs it mentions you need to connect to port 7349 to call RPC functions, so we can clarify that section?

I put the lua module in the modules folder and restarted the docker and see that the module I have deployed is recognized by looking at the logs. But when I run the RPC call with the code below;

    var payload = "{\"PokemonName\": \"pikachu\"}";
    var rpcid = "update_metadata";
    var pokemonInfo = await client.RpcAsync(session, rpcid, payload);

“RPC function not found” exception is thrown.

Then I saw the Heading “https://heroiclabs.com/docs/install-configuration/#server-ports” and I thought that i should make the rpc calls with a client created with 7349 port. This is may be due to my over thinking. just a misunderstanding.

Now I see that i don’t need that. But I dont see what the problem is.

The lua module I deployed is below;

local nk = require(“nakama”)

local function update_metadata(context, payload)

local user_id = context.user_id  
local metadata = nk.json_decode(payload)

local status, err = pcall(nk.account_update_id, user_id, metadata, nil, nil, nil, nil, nil, nil)

if (not status) then
  nk.logger_info(("Account update error: %q"):format(err))
end
return payload

end

nk.register_req_before(update_metadata, “update_metadata”)

Thanks for the quick response.

Your problem is this line:

nk.register_req_before(update_metadata, “update_metadata”)

That’s not a correct RPC function registration. Check the RPC documentation section and you’ll see you should use this instead:

nk.register_rpc(update_metadata, "update_metadata")

Oh yea. Thank you.

It was actually like that but it wasn’t working that way either. It seems that it was due to another reason. I tried lots of other things, we moved everything to docker from kubect etc. and it became a mess. Now I did everything by the book and now it is working with your help.

Thanks again. I am really impressed with your quick response.