【发布时间】:2014-03-22 13:25:57
【问题描述】:
我遵循了创建 RPC 客户端和服务器here 的简单示例。基本上,步骤是:
- 创建一个有效的 .x 文件——在本例中为 add.x
- rpcgen -a -C add.x
- 在 add_server.c 中添加 printf() 行,检查服务器是否收到客户端请求
- make -f Makefile.add
- ./addserver
- 在另一个终端,运行./addclient localhost
这应该在第一个终端打印一些东西,但在我的情况下它似乎没有打印任何东西。我正在使用 ssh 在学校服务器上运行代码。也许我应该指定端口,即 127.0.0.1?无论如何,我不确定这是否能解决问题。有什么想法吗?
add.x 的代码是:
struct numbers {
int num1;
int num2;
};
program ADDITION {
version ADDITION_1 {
int ADD(numbers)=1;
} = 1;
} = 0x2fffffff;
所有其他文件都是由 rpcgen 从 add.x 生成的
add_server.c 中添加的 printf() 是:
/*
* This is sample code generated by rpcgen.
* These are only templates and you can use them
* as a guideline for developing your own functions.
*/
#include "add.h"
int *
add_1_svc(numbers *argp, struct svc_req *rqstp)
{
static int result;
/*
* insert server code here
*/
printf("Got the client request!");
return(&result);
}
【问题讨论】:
-
端口是计算机上的连接点(例如 HTTP 通常使用端口 80),而不是 IP 地址,所以忽略它。
rpcinfo有没有告诉你什么?除此之外,如果没有代码,真的很难猜出可能出了什么问题。 -
是的,rpcinfo 确实告诉我一些事情。