SaravananMP
asked on
Windows RPC - Events/Callbacks
Hi
We're developing a distributed computing app, wherein we use RPC for the communication between client and server. The server has two threads: One interacting with the client and the other waiting for user input. When there is an user input, the user thread should post a message to the server thread and the server thread should pass this on to the client as an event. Is this feasible to be implemented in RPC? If so, any idea on how to implement this?
Thanks.
Regards
Saravanan.
We're developing a distributed computing app, wherein we use RPC for the communication between client and server. The server has two threads: One interacting with the client and the other waiting for user input. When there is an user input, the user thread should post a message to the server thread and the server thread should pass this on to the client as an event. Is this feasible to be implemented in RPC? If so, any idea on how to implement this?
Thanks.
Regards
Saravanan.
ASKER
Hi
Thanks for your response. The issue here is not passing data from one thread to the other. It's triggering an event from the Server to the Client.
In a COM interface, we declare an event as,
dispinterface _<InterfaceName>Events
{
methods:
[id(1), helpstring("method ValueChanged")] void ValueChanged (VARIANT varSelectedValue);
}
The server would invoke this by Fire_ValueChanged(varSel);
The client would implement something like OnValueChanged(VARIANT varSel)
{
}.
In the same way, does RPC provide some ways to trigger an event from the server to the client? Any special attribute to mentioned in the IDL to specify an event? Please clarify.
Thanks.
Thanks for your response. The issue here is not passing data from one thread to the other. It's triggering an event from the Server to the Client.
In a COM interface, we declare an event as,
dispinterface _<InterfaceName>Events
{
methods:
[id(1), helpstring("method ValueChanged")] void ValueChanged (VARIANT varSelectedValue);
}
The server would invoke this by Fire_ValueChanged(varSel);
The client would implement something like OnValueChanged(VARIANT varSel)
{
}.
In the same way, does RPC provide some ways to trigger an event from the server to the client? Any special attribute to mentioned in the IDL to specify an event? Please clarify.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
[ uuid ([...]),
version(1.0),
pointer_default(unique)
]
interface IEventSink
{
unsigned int PutEvent ( [in] unsigned int nEventId,
[in] unsigned int nSize,
[in, size_is(nSize), ] unsigned char* pAdditionalData
);
}
In your interacting thread, you'd now
// Bind to RPC server first
for (;;) {
// wait for the user input thread to send something
// ...
// pass it over
PutEvent ( nMsgId, 0, NULL); // no additional data
}