[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.remoting

callback, asynchronous callbacks and all that crazy stuff

Phil Greg

11/5/2004 4:53:00 PM

Hi,
in my test project I successfully implemented two-way communication between
the client and the server, using an interface derived client, like such:
public __gc __interface IClientEvents //This is an interface that will be
implemented by the client
{ //so that we can have a two way
communication (Server->Client as well as Client->Server)
public:
void SendEventMessage(String* strMessage);
};

public __gc __interface IGreeterServer //This is the interface that will
be implemented by the remote object on the server
{
int RegisterClientWithServer(IClientEvents* clientEvents); //The client
passes a reference to itself for Server->Client communication
void RaiseEvent(int instanceNumber);
};

Now, I'm able to successfully call the functions on my client from my
server. However I keep seeing stuff about callbacks and async callbacks, and
I'm not too sure what those are, and if I risk getting into trouble if I
don't use them (supposing I don't already use them!). Can anyone make this
clearer to me? Thanks in advance!
1 Answer

Ken Kolda

11/6/2004 12:46:00 AM

0

The main synch/asynch issue that's probably relevant to you is when one of
your clients calls RaiseEvent() on your server object. Presumably, the next
thing that happens is that you loop through the clients' callback interfaces
and invoke each in succession. The problem is: what if one of the clients is
poorly behaved and hangs during the callback? Now the client which called
RaiseEvent() is also stuck. Or, what if there are 1000 clients and it takes
a second to perform the callback on each? Then your client that called
RaiseEvent() is effectively hung.

To deal with this, you can do one of a few things:

1) Wrap your clients' event callbacks in delegates and invoke them
asyncronously. This allows multiple clients to be notified concurrently on
different threads. The drawback is that you can exhaust your threadpool and
thus make it difficult to process new inboudn requests.

2) Spin up a thread in your RaiseEvent() method and perform the callbacks in
that thread. Thus, the client that called RaiseEvent() will return
immediately.

The only snag either way is that you can't assume that your clients have all
received the message by the time RaiseEvent() returns. It's more of a
fire-and-forget model.

The right implementation depends on your needs and what the event means to
your clients. You just have to decide whether asynchronous makes sense for
your purposes or not.

Hope that helps -
Ken




"Phil Greg" <PhilGreg@discussions.microsoft.com> wrote in message
news:D5FBC703-C442-49F5-8162-27E007659237@microsoft.com...
> Hi,
> in my test project I successfully implemented two-way communication
between
> the client and the server, using an interface derived client, like such:
> public __gc __interface IClientEvents //This is an interface that will
be
> implemented by the client
> { //so that we can have a two way
> communication (Server->Client as well as Client->Server)
> public:
> void SendEventMessage(String* strMessage);
> };
>
> public __gc __interface IGreeterServer //This is the interface that will
> be implemented by the remote object on the server
> {
> int RegisterClientWithServer(IClientEvents* clientEvents); //The
client
> passes a reference to itself for Server->Client communication
> void RaiseEvent(int instanceNumber);
> };
>
> Now, I'm able to successfully call the functions on my client from my
> server. However I keep seeing stuff about callbacks and async callbacks,
and
> I'm not too sure what those are, and if I risk getting into trouble if I
> don't use them (supposing I don't already use them!). Can anyone make this
> clearer to me? Thanks in advance!