我看到了这个question,但它似乎并不适用。
继承我的功能,它在客户端代码中完成了最重要的工作:
void
database_1(char *host, char *action, char *message)
{
printf("Action: %s\n", action);
printf("Message: %s\n", message);
CLIENT *clnt;
rpc_args *result_1;
//struct rpc_args action_1_arg;
//rpc arguments struct to pass to server
struct rpc_args *args = malloc(sizeof(struct rpc_args));
char *id = generate_id();
if (strcmp(action, "GET") == 0) {
printf("Client: GET request\n");
strcpy(args->action, action);
strcpy(args->id, id);
} else if(strcmp(action, "PUT") == 0) {
printf("Client: PUT request\n");
strcpy(args->action, action);
strcpy(args->id, id);
strcpy(args->message.content, message);
}
#ifndef DEBUG
clnt = clnt_create (host, DATABASE, ASSIGNMENT_7, "udp");
if (clnt == NULL) {
clnt_pcreateerror (host);
exit (1);
}
#endif /* DEBUG */
result_1 = action_1(args, clnt);
if (result_1 == (rpc_args *) NULL) {
clnt_perror (clnt, "call failed");
}
free(args);
#ifndef DEBUG
clnt_destroy (clnt);
#endif /* DEBUG */
}
这是我的输出:
./database_client eecslinab3.case.edu GET
running client, main
Action: GET
Message: (null)
hostname is eecslinab3
The process id is 24697
The unique id is eecslinab324697
Client: GET request
call failed: RPC: Can't encode arguments
Database.x
struct message {
char content[2000];
};
struct rpc_args {
char action[20];
char id[1024];
struct message message;
};
program DATABASE {
version ASSIGNMENT_7 {
rpc_args ACTION(struct rpc_args) = 1;
} = 1;
} = 0x20fff100;
答案 0 :(得分:0)
一位朋友帮我解决了这个问题,但没有给我很多关于修复工作原因或方法的细节。基本上我减少了我的struct中的char数组大小并且它工作了。与您可以通过UDP发送的数据限制有关。
struct rpc_args {
char action[20];
char id[80];
char message[80];
};
program DATABASE {
version ASSIGNMENT_7 {
rpc_args ACTION(struct rpc_args) = 1;
} = 1;
} = 0x20fff100;