Search code examples
crpcdistributed-computingxdr

Communication Between 2 Servers (C Language)


I'm trying to make a distributed system where a client sends some information to one server, the server receives the message and forwards it to all other servers. The system utilises RPC and XDR as it's interface definition language.

I got the part where the server receives the message. But I'm unable to forward the message to other servers. Even if I manage to forward the message, it's only printed if the client also sends a message to that specific server, i.e., along with that message.

For Ex: If I send a message Hello to server A and server A is supposed to forward it to server B as well. Server B gets the message and doesnot print it. Instead, when I send a message Hi to server B, it prints HELLOHI. That means B got the message and didn't quite print it.

Any suggestions as to why that might be happening? I'm using rpc_broadcast to broadcast the message received from client to other servers.

Edit1: Here's the method that I try to call when a broadcast is received by all servers. I'm jus trying to print a static HELLO THERE to see if it's working before implementing my logic there.

int *
pass_details_1_svc (xaction_args *argp, struct svc_req *rqstp)
{
    int *i;
   printf("HELLO THERE");   
   return i;
}

And here's the rpc_broadcast call that I do when I receive a message from the client:

xaction_args ag; ag.passMsg="Hello";
rpc_broadcast(others,TICKER_PROG,TICKER_VERS,PASS_DETAILS,(xdrproc_t)xdr_xaction_args,&ag);

passMsg is a variable in the structure defined in the XDR file.


Solution

  • Adding \n works because it flushes your current printf buffer. When you normally call printf, it is not necessary that OS immediately outputs that too. It can buffer for a while and execute at some unpredictable time. Flushing out the print buffer ensures immediate printing.

    Alternately you could have used some system call which is not buffered, for instance perror()

    So it's not kinda funny, it is standard logical behavior by design