2012-04-07 43 views
0

我想创建一个示例RPC程序来了解更多关于它。它所做的只是承认在我开始进一步干预之前,我有一个正在运行的RPC程序。之前在这里提我的问题是我的代码,它非常简单:RPCGEN介绍使用C - 不能创建客户端

/* 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作为我的编程语言。在构建项目时我没有问题。

提前感谢您的时间。

回答

0

在有问题的行:

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

更改最后一个 “UDP” 为我工作参数。

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