rpc:运行c程序时未注册程序

问题描述

大家好,我是uniuni学生,我正在尝试使用rpc协议在c语言中制作一个简单的计算器。 我遇到的问题: 我收到错误消息:137.155.148.29 RPC:program not registered

我还创建了另一个程序,该程序使用与我的服务器(服务器是uni服务器)相同的IP地址来计算盒子的表面积和体积,并且该程序可以正常运行。

这是我的主文件:

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


float
compute_6(char *host,float a,float b,char op)
{
    CLIENT *clnt;
    float  *result_1;
    values  add_6_arg;
    float  *result_2;
    values  sub_6_arg;
    float  *result_3;
    values  mul_6_arg;
    float  *result_4;
    values  div_6_arg;

if(op=='+'){

    add_6_arg.num1=a;
    add_6_arg.num2=b;
    add_6_arg.operation=op;

    clnt = clnt_create (host,COMPUTE,COMPUTE_VERS,"udp");
    if (clnt == NULL) {
        clnt_pcreateerror (host);
        exit (1);
    }

    result_1 = add_6(&add_6_arg,clnt);
    if (result_1 == (float *) NULL) {
        clnt_perror (clnt,"call failed");
    }

    clnt_destroy (clnt);

    return (*result_1); 
}

else if(op=='-'){
    sub_6_arg.num1=a;
    sub_6_arg.num2=b;
    sub_6_arg.operation=op;
    
    clnt = clnt_create (host,"udp");
    if (clnt == NULL) {
        clnt_pcreateerror (host);
        exit (1);
    }

    result_2 = sub_6(&sub_6_arg,clnt);
    if (result_2 == (float *) NULL) {
        clnt_perror (clnt,"call failed");
    }

    clnt_destroy (clnt);

    return (*result_2); 
}

else if(op=='*'){
    mul_6_arg.num1=a;
    mul_6_arg.num2=b;
    mul_6_arg.operation=op;

    clnt = clnt_create (host,"udp");
    if (clnt == NULL) {
        clnt_pcreateerror (host);
        exit (1);
    }

    result_3 = mul_6(&mul_6_arg,clnt);
    if (result_3 == (float *) NULL) {
        clnt_perror (clnt,"call failed");
    }

    clnt_destroy (clnt);

    return (*result_3); 
}

else if(op=='/'){
    if(b==0){
        printf("You are trying to divide by zero. Please insert a valid number.\n");
    exit(0);
    }
    else{
        div_6_arg.num1=a;
        div_6_arg.num2=b;
        div_6_arg.operation=op;

        clnt = clnt_create (host,"udp");
        if (clnt == NULL) {
            clnt_pcreateerror (host);
            exit (1);
        }

        result_4 = div_6(&div_6_arg,clnt);
        if (result_4 == (float *) NULL) {
            clnt_perror (clnt,"call failed");
        }

        clnt_destroy (clnt);

        return (*result_4);
        }   
    }

}


int
main (int argc,char *argv[])
{
    char *host;

    float number1,number2;
    char oper;
        printf("Enter the 2 numbers followed by the operation to perform:\n");
        scanf("%f",&number1);
        scanf("%f",&number2);
    scanf("%s",&oper);

    host = argv[1];
    printf("Answer= %f\n",compute_6 (host,number1,number2,oper));
        exit(0);

}

和我的idl.x文件

struct values{
    float num1;
    float num2;
    char operation;
};

/*Programme,version and procedure definition*/

program COMPUTE{
    version COMPUTE_VERS{
        float ADD(values) =1;
        float SUB(values)=2;
    float MUL(values)=3;
    float DIV(values)=4;
    } =6;

} = 456123789;

步骤: 创建idl.x文件后 我用过

rpcgen idl.x

生成文件

然后我创建了idl_funcs.c文件

最后我用

编译
cc idl_funcs.c idl_xdr.c idl_clnt.c -o client

最后

./client 137.155.148.29 

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...