RPC Client gives Can't encode arguments

匿名 (未验证) 提交于 2019-12-03 01:02:01

问题:

I'm trying to write the simpliest client in RPC with this code:

#include <stdio.h> #include <stdlib.h> #include <rpc/rpc.h>  int main(int argc, char *argv[]){   int stat;   char out;     char in='f';    if(stat=callrpc(argv[1],0x20000001, 1, 1, (xdrproc_t)xdr_void, &in, (xdrproc_t)xdr_char, &out)!=0){       clnt_perrno(stat);       exit(1);   }    exit(0); }

It compiles, but when I try to run it, it gives me a "RPC: Can't encode arguments"

EDIT: Actually the server do not recieve any argument neither it send back anything, that's why I put a xdr_void added &in and &out to avoid segmentation fault error.

回答1:

You are missing some parentheses:

if (stat = callrpc(...) != 0)

is evaluated to

if (stat = (callrpc(...) != 0))

which always assigns 1 to stat in case of an error, which is RPC_CANTENCODEARGS. You need

if ((stat = callrpc(...)) != 0)

to get the real error code and message printed in

clnt_perrno(stat);


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!