在RPCGen中将字符指针从客户端传递到服务器

阿瑞什·拉梅什(Aarish Ramesh)

我正在尝试从rpc客户端向rpcgen中的服务器发送字符指针,以下是服务器和客户端程序

RPC生成器的RPC程序

struct clientinput {
    char * optype;
    char * word;
};

program DICTIONARY_PROG {
    version DICTIONARY_VERS {
        int USEDICTIONARY(clientinput) = 1;
    } = 1;
} = 0x23451113;

RPC服务器

    #include "dictionary.h"

    int *
    usedictionary_1_svc(clientinput *argp, struct svc_req *rqstp)
    {
        static int  result;
        char *optype = (char*)malloc (10);
        char *word = (char*)malloc (10);

        char *a = argp->optype;
        char *b = argp->word;

        printf("Optype is %s\n", a);
        printf("Word is %s\n", b);

        printf("The optype is %s\n", strcpy(optype, argp->optype));
        printf("The word is %s\n", strcpy(word, argp->word));
        /*
         * insert server code here
         */

        return &result;
    }

RPC客户端

#include "dictionary.h"


void
dictionary_prog_1(char *host, char *optype, char *word)
{
    CLIENT *clnt;
    int  *result_1;
    clientinput  usedictionary_1_arg;

    //strcpy(usedictionary_1_arg.optype, optype);
    //strcpy(usedictionary_1_arg.word, word);

    usedictionary_1_arg.optype = optype;
    usedictionary_1_arg.word = word;

    printf("Optype input is %s\n",usedictionary_1_arg.optype);
    printf("Word input is %s \n",usedictionary_1_arg.word);

#ifndef DEBUG
    clnt = clnt_create (host, DICTIONARY_PROG, DICTIONARY_VERS, "udp");
    if (clnt == NULL) {
        clnt_pcreateerror (host);
        exit (1);
    }
#endif  /* DEBUG */

    result_1 = usedictionary_1(&usedictionary_1_arg, clnt);
    if (result_1 == (int *) NULL) {
        clnt_perror (clnt, "call failed");
    }
#ifndef DEBUG
    clnt_destroy (clnt);
#endif   /* DEBUG */
}


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

    if (argc < 2) {
        printf ("usage: %s server_host\n", argv[0]);
        exit (1);
    }
    host = argv[1];
    optype = argv[2];
    word = argv[3];

    dictionary_prog_1 (host,optype,word);
exit (0);
}

这是服务器端的输出

Optyep is a
Word is e
The optype is a
The word is e

我在这里遇到的问题是,只有从服务器传递到客户端的字符指针的第一个字符才被打印出来。我尝试了使用字符指针的可能组合,但找不到原因。那么有人可以帮我找出原因吗?

埃里克·福汀(Eric Fortin)

通过查看文档,RPCGen需要一些帮助来区分单个字符参数和实际字符数组,因为所有参数都作为指针传递。为了让它知道您想要一个字符数组,又称字符串,您需要string像下面这样在结构声明中使用关键字:

struct clientinput {
    string optype<>;
    string word<>;
};

答案也对此进行了说明,并且此博客文章中的示例与您要完成的任务类似。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在 NEXTJS 中将变量从客户端传递到服务器端

如何在Meteor中将数据从服务器传递到客户端

将var从服务器传递到客户端

在Flask中将带有Jquery和JSON的Javascript数组从客户端传递到服务器端

如何在js中将js中的变量从服务器端传递到客户端

如何使用jquery ajax和node js在快速框架中将数据从客户端传递到服务器?

将AD用户从客户端传递到IIS服务器再传递到DB服务器

将数据从客户端传递到服务器端

无法将客户端消息传递到服务器端

jhipster客户端将实体过滤器传递到服务器端?

我如何将Java对象从服务器端传递到客户端

客户端数据到服务器端

如何在Google Earth Engine中将值从服务器复制到客户端?

如何将jwt从swift客户端传递到node.js服务器

NumberFormatException,同时将udp从客户端传递到服务器的数据转换为

使用Flask将JSON数据从服务器传递到客户端

流星将数据从客户端传递到服务器

如何将CSRF令牌从服务器传递到客户端?

将Facebook访问令牌从移动客户端传递到服务器并进行处理

如何安全地将Redux存储从服务器传递到客户端

将数组从NodeJS服务器传递到客户端?

如何与使用从客户端传递到服务器的参数用于ActionCable的通道保持连接?

NodeJS - 使用 ajax 将数组从客户端传递到服务器

Delphi EMS FireDAC:如何使用EMS将参数从客户端传递到服务器?

是否可以将变量从客户端脚本传递到服务器脚本?

无法将值从服务器传递到客户端的Javascript不起作用

如何使用 AJAX 将图像从服务器传递到客户端 Flask

客户端服务器消息传递

客户端1到服务器到客户端2的实时通信