question about synchronous message passing


I want to implement synchronous communication between two computers(A, B) with the Qnet and gns. My problem is sometimes I need A to be server, and sometimes the B to be server. Could this situation be done? Any suggestions?

Thanks in advance!


There are a few different approaches. The symmetric solution would be to have a server and client on each side. If the server and client needs to be in the same process, you could use threads.

Another approach is to realize that a message passing server can look like a client. A visual might help:

Normal Mode

Client --------------------- sends message -------> Server
server does something
Client <-------------------- reply message ------- Server

Reverse Mode

Client Checks in ------------- send message -------> Server receives but does not reply
Server wants to act like a client now
Client <---------------------- reply message -------- Server replies with message
Client does something
Client responds --------------send message --------> Server receives but does not reply

Thanks for you reply!

I noticed that always client sends message first and server reply message. Could this be reversed?
Such as server name_attach some global name, send messages then client name_open that global name and receive message, can this situation be done?

Thanks again!

You can build something with QNX message passing that works this way, but the answer to your question is no, there is no way to send a message before a process has set up a channel to receive the message.

Thanks a lot.
Could you give me a hint to do QNX message passing in a distributed way execept tcp/udp?

If you mean that you want to broadcast, there is no way that will have the efficiency of udp. You would have to have multiple messages sent and/or received.

Thanks for your help, I think UDP maybe a good choice.