문제

I followed the simple example of creating RPC client and server here. Basically, the steps are:

  1. Create a valid .x file--in this case, add.x
  2. rpcgen -a -C add.x
  3. add a printf() line in add_server.c to check whether the server gets the client request
  4. make -f Makefile.add
  5. ./addserver
  6. in another terminal, run ./addclient localhost

This should print something in the first terminal, but it doesn't seem to print anything in my case. I am running the codes on a school server by using ssh. Perhaps I should specify the port, i.e., 127.0.0.1? Regardless, I'm not sure if this will solve the problem. Any ideas?


The code for add.x is:

struct numbers {
    int num1;
    int num2;
};

program ADDITION {
    version ADDITION_1 {
        int ADD(numbers)=1;
    } = 1;
} = 0x2fffffff;

All the other files are generated by rpcgen from add.x


The printf() addition in add_server.c is:

/*
 * 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);
}
도움이 되었습니까?

해결책

Oh! The RPC server is buffering its output. I found it by digging into the add_svc.c code to add debugging statements. Printing something after the call to the remote call fixed it.

That's a terrible solution, though, because that code is automatically generated.

Instead, you have two choices.

  • After your printf() call, flush the output buffers with fflush(stdout);
  • Add a carriage return (\n) to the end of your output string.

Either will work fine.

For the reasons behind this, see this question.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top