Search code examples
crpc

C Code, RPC Error "RPC: Can't encode arguments"


I saw this question but it doesn't seem to apply.

Heres my function which does most the heavy lifting in the client code:

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 */
}

Here's my output:

./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;

Solution

  • A friend helped me solve the problem but didn't give me much details about why or how the fix works. Basically I reduced the char array sizes in my struct and it worked. Has something to do with the limit of data you can send over 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;