0

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.

proctr
  • 452
  • 4
  • 15
  • 1
    This is like predicting the weather from someone saying "I see grass outside". Or something. In other words, I think this is lacking in detail. – unwind Oct 23 '12 at 09:18
  • My apologies..I'll update the question.. – proctr Oct 23 '12 at 09:19
  • 2
    When you sending from serverA to serverB put the "\n" at the end of `Hello` to indicate end of transmission – Memos Electron Oct 23 '12 at 09:20
  • Hey memosdp, thanks. Adding a `\n` worked. Funny how a endline character can make stuff work. Add your comment as an answer below so that I can accept it. Thanks :) – proctr Oct 23 '12 at 09:27
  • doesn't worth anything more than a comment ... despite this @fayyazkl needs it more for the effort – Memos Electron Oct 23 '12 at 09:46
  • This is called _line buffering_. The `stdout` stream (the one that `printf` outputs to) is buffering until a new line is encountered in the text stream or `fflush(stdout);` is performed. – Hristo Iliev Oct 23 '12 at 15:51

1 Answers1

1

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

fkl
  • 5,412
  • 4
  • 28
  • 68