Let’s start directly with an example. I have a single-thread server
that must handle messages from two clients on different channels:
client1 -----> server <----- client2
If I desing a server like this, I directly jump into a dark hole: the
server will remain blocked within a MsgReceive call completely
ignoring the second client.
In this case it would be usefull to receive some kind of signal when
I effectively need to receive a message from a client. A possible
solution that I’ve thought is to create 2 threads, each one blocked
within a MsgReceive call and than deliver a signal to the main idle
tread. The problem here is that the server shold be single-threaded.
Is there any way to perform asyncronous message passing on the server
side (MsgReceive)?
Another question:
In the example above the server must be able to do something like
this:
receive a message from client1, process this message then deliver a
message to the second client. The trick here is that: the server is
probably locked on a MsgReceive from the client2, and as read in the
documentation I can’t break the message direction (client2->server).
The client2 should instead ask the server and the server reply with
the data that must be passed. The MsgDeliverEvent in this case would
be usefull but it safe to perform it while a thread is already
waiting in a MsgReceive call?
scheme from client1 → server ← client2 perspective
- server is blocked within 2 MsgReceive calls
- client1 sends a message to the server (chn 1) to be delivered to
client2 - thread1 (chn 1) in server unblocks, performs some data analisis,
and send a MsgDeliverEvent to client2 (chn 2) - client2 (wich may/may not be blocked) receives the signal and sends
the request message to the server thread 2 - thread 2 will receive the message, send the data and return to the
blocked state.
Is this design possible?
The important thing here is to have the 2 clients completely free
(they’re not blocked) since they must be ready to handle user
interaction with some form of ui in a resource limited system