Hii everybody

I was building RPC based server-client application

I have a struct called event contains

int type
long int time

I have a function in a server that return (*event)

event *
log_1_svc(event *argp, struct svc_req *rqstp)
    static event*  result;
result = (struct event*)malloc (3 * sizeof (struct event));
while (i <3)
            result[i].type_id = i;
            result[i].time = i;
return &result


what I want is to receive results at client using this pointer

here is the code at client's site:

log_prog_1(char *host,int client_type,int type_id,long int time)

event  *result_1;

result_1 = log_1(&log_1_arg, clnt); // this calls the function in server and gurantee that the result is returned an address to pointer

int i =0;
        while (i<3)
            printf ("Type: %d\n",result_1[i].type_id);
            printf ("Time: %ld\n",result_1[i].time);

this code works but it seems that it returns addresses not values (the numbers shown in client terminal is different from ones in server's terminal).

I tried to let the server return result

return result;

not the address of result (as written previously)

return &result;

it worked but only the first item printed correctly in client's terminal the other 2 items are 0's

please provide me with a solution and thanks in advance : )

Recommended Answers

All 5 Replies

I'm assuming client and server are two separate programs. Two processes can not share the same memory location. How to pass data between client and server will depend on the operating system. Its even more complicated when client and server run on different computers.

Are the client and server separate processes? Or are they threads inside the same process?

they are sperate processes ... and I think that RPC handles the different addressing thing between memory ... but for now assuming that I'm running them on the same computer so addresses won't change :)

You can't just pass addresses between separate processes on modern operating systems because each process has its own virtual memory. This would include using an RPC (remote procedure call). That would work for old monolithic systems such as DOS, but I don't think it will work with any Windows systems since NT, and it certainly won't work with Linux, Unix, etc. An RPC will marshal the procedure argument data at the sending end, and unmarshal it at the receiving end, but you can't send a structure with addresses in it. You have to send the things the addresses refer to themselves.

So, just to make sure we are clear, what EXACTLY are you trying to do? Describe the environment (client, server, interprocess communications methods, etc) that you are trying to accomplish, in as much detail as possible.

You are in both cases asking the file to return the address
When u write return &result - it returns the address
Also, since in this case *result is the pointer variable, when u say return result it again returns the address of *result.

To get the program to return the value, type the following :

return *result

It then returns the value of result.. This should work, pls let me know whether it does or not !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.