I'm having difficulties writing the rpc function. Specifically, I don't know how to pack a function name and input argument into a message body, send the message, set and unpack reply, and return result and error code. I know how to create the socket, request aconnection from the server etc. , but I'm totally stuck here.
It's a relatively simple rpc package consisting of user-stub and server-stub.

Really? I did not know. The links on that website don't work, though. Ok, let me explain it.

I have a main function and a test function.

#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>

extern int errno;

#define  MAXLEN 512

main(int argc,char *argv[]) {
    // You cannot change anything inside this function
    char input[MAXLEN], output[MAXLEN];
    int pid;
    printf("Enter your Zodiacal sign ended by a return: ");
    printf ("So your sign is %sn", input);
    rpc("test", input, output);
        printf( "Well, %s n", output);
    // Additional tests
    if (rpc("test","the two Gemini", output) < 0)
          printf("Procedure test not foundn");
           printf( "Besides, %s n", output);
    if (rpc("anotherone","the two Gemini", output) < 0)
       printf("Procedure anotherone not foundn");
           printf( "Besides, %s n", output);
} // main

And the test function:


test (char argument[], char result[]) {
   sprintf (result, "People born in the house of %s are exceptional", argument);
} // test

So test function goes into the server. You basically just input any Zodiac sign and it's supposed to print the test function via rpc, I think. So now I have the basics such as created the sockets, connected it etc. , but I don't know how to do the call to the test function. I might have explained it a little weird in the OP.

Edited 4 Years Ago by XodoX

This article has been dead for over six months. Start a new discussion instead.