RPC客户端提供了无法连接code参数 [英] RPC Client gives Can't encode arguments

查看:140
本文介绍了RPC客户端提供了无法连接code参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写的RPC客户端simpliest此code:

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);
}

它编译,但是当我尝试运行它,它给了我一个RPC:无法连接code参数

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

编辑:其实服务器没有收到任何说法既不它发回任何东西,这就是为什么我把 xdr_void 添加&功放;在&放大器;退出来避免分段错误

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.

推荐答案

您缺少一些括号:

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

进行评估,以<​​/ P>

is evaluated to

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

它总是分配 1 与stat 中的错误,这是的情况下, RPC_CANTEN codeARGS 。您需要

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

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

要得到真正的错误code和消息

to get the real error code and message printed in

clnt_perrno(stat);

这篇关于RPC客户端提供了无法连接code参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆