【问题标题】:RPCGEN introduction using C - can not create clientRPCGEN 介绍使用 C - 无法创建客户端
【发布时间】:2012-04-07 18:57:44
【问题描述】:

我正在尝试创建一个示例 RPC 程序以了解有关它的更多信息。它所做的只是承认我手头有一个工作的 RPC 程序,然后我才开始进一步干预它。在这里提到我的问题之前是我的代码,它非常简单:

/* myrpc.x file*/
program MESSAGEPROG {
   version EVALMESSAGEVERS {
     int EVALMESSAGE(string) = 1;
   } = 1;
} = 0x20000002;

远程方法如下:

/* Remote method on a .c file */
#include <stdio.h>
#include "myrpc.h" 

int * evalmessage_1_svc(char **msg, struct svc_req *req)

{
    static int result = 0;
    printf("Message is: %s,\n",*msg);
    return (&result);
}

最后测试文件如下:

#include <stdio.h>
#include "myrpc.h" 

main(int argc, char **argv)

{
    CLIENT * clnt;
    char * server;
    char * msg;

    server = argv[1];
    msg = argv[2];

    clnt = clnt_create(server, MESSAGEPROG, EVALMESSAGEVERS, "visible");
    if (clnt == (CLIENT *)NULL) { printf("Failure\n"); }

    int * answer;
    answer = evalmessage_1(&msg,clnt);

    clnt_destroy(clnt);
    exit(0);

}

我的问题是,我得到输出:“失败”,表明我无法创建客户端。我使用 ubuntu/linux 作为我的平台并使用 C 作为我的编程语言。我在构建项目时没有遇到任何问题。

提前感谢您的宝贵时间。

【问题讨论】:

    标签: c rpc


    【解决方案1】:

    在有问题的行:

    clnt = clnt_create(server, MESSAGEPROG, EVALMESSAGEVERS, "visible");
    

    将最后一个参数更改为“udp”对我有用。

    clnt = clnt_create(server, MESSAGEPROG, EVALMESSAGEVERS, "udp");
    

    【讨论】:

      猜你喜欢
      • 2013-05-06
      • 1970-01-01
      • 2015-01-15
      • 2014-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-09
      • 2018-05-27
      相关资源
      最近更新 更多