Re: delegate question
From: Nicholas Paldino [.NET/C# MVP] (mvp_at_spam.guard.caspershouse.com)
Date: 01/10/05
- Next message: ali galacta: "Re: Proxy Authentication required"
- Previous message: manuel aldana: "delegate question"
- In reply to: manuel aldana: "delegate question"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 10 Jan 2005 14:27:20 -0500
Manuel,
The reason it needs an object graph is because it needs the type
information of the method that the delegate is attached to. Also, you most
definitely do NOT want to make this serializable, as the event will fire on
the server, and never get to you (a copy of your client will be sent to the
server). Rather, you want to have an object with the event handler method
derive from MarshalByRefObject. This way, when the event is fired, the
event is remoted back to the client, and not a copy.
I would recommend doing the following. First, create an interface that
has the signatures of the event handlers for the events that you will be
firing. Implement this interface on the object you want to handle the
events.
Create, in a separate assembly, a class which takes an instance of this
interface in the constructor, and derives from MarshalByRef. Create methods
which have the signature of your event handlers on this class as well. In
the methods, call the implementation on the interface.
Pass this shim class from the client (with the reference to the client's
implementation to the interface) to the server, and let the server fire the
events to the shim.
This way, you can pass the assembly with the shim to the server, and not
have to worry about the server needing all the type information for your
client.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
"manuel aldana" <noSpamEverAgain@gmx.de> wrote in message
news:34g2p1F47u41jU4@individual.net...
> hi folks.
>
> i am writing an distributed .net game-application with c#. there are
> clients and a game-server.
> the game-server uses events -> delegates to use callbacks to the
> game-clients.
>
> there is one thing i don't understand. when i start the app, the
> client-runtime throws serialization exceptions of classes that are not
> relevant for my client.
> the runtime claims these server-classes to be serializable, which are
> referenced by the class, where my delegate-vars are called.
>
> i read in varios papers that it is neccessary, that the object-graph of
> the class where my event "lives" needs to be serializable. but why?? as i
> said the client does not access server-classes at all (apart from the
> remote-interface). apart from that it is a very dirty design (my client
> needs .dlls of server classes) and slow (object are serialized over the
> bottlenecked network).
>
> maybe there is a setting in my server.config i haven't found yet?
>
> any help very appreciated. thnx.
>
> x-post f'up set.
>
> --
> manuel aldana
> above adress not valid -> use: aldana[at]cs.tu-berlin.de
- Next message: ali galacta: "Re: Proxy Authentication required"
- Previous message: manuel aldana: "delegate question"
- In reply to: manuel aldana: "delegate question"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|