Solved

Windows RPC - Events/Callbacks

Posted on 2004-08-05
5
319 Views
Last Modified: 2010-04-01
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.
0
Comment
Question by:SaravananMP
  • 2
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 11739640
It is possible. Passing messages between threads is to be done the 'usual' way, the RPC implementation also is quite 'painless', e.g

[ 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

}
0
 

Author Comment

by:SaravananMP
ID: 11752752
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.

0
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 11753678
>>RPC provide some ways to trigger an event from the server to the client?

Well, the way is to call a remoted function that signals the event to the client/server, there's no special IDL attribute for that.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now