Re: delegate question

From: Nicholas Paldino [.NET/C# MVP] (mvp_at_spam.guard.caspershouse.com)
Date: 01/10/05


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 


Relevant Pages

  • Re: "Insufficient state to deserialize the object" error
    ... The delegate itself is a serializable object, so both client and server need ... > that requires serialization? ... >> If any of the assemblies are being loaded from the mapped drive, ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Delegates, Client-side Events and Remoting
    ... server without requring server to know about the concrete class of client ... Asynchronous delegate are best in that scenario; ... For client to server communication, however -- it is just a forward method ... To abstract in a "layer of delegation between the proxy class instance on ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Copy a remote object localy
    ... > whole object on the SubmitBag() call instead of just sending a proxy. ... > Is there a way to kind of force this serialization? ... >> call to my server object. ... >> client and then to host it on the central server, ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: "Insufficient state to deserialize the object" error
    ... code snippet I sent is called "Inexus.dll" (namespace INexusStuff). ... on the Client side. ... Back on the Server side there is another module with the ... The code containing the Server side delegate, ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: YANQ (Yet another newbie Question)
    ... Create client access to a remote server by using Visual C++ .NET ... > when the client tries add an event to a public delegate on the server. ...
    (microsoft.public.dotnet.framework.remoting)

Loading