Re: little more help on remoting?
From: Patty O'Dors (PattyODors_at_discussions.microsoft.com)
Date: 08/13/04
- Next message: Patty O'Dors: "Re: [Newbie] What are ASP.NET and ADO.NET ?"
- Previous message: BMermuys: "Re: Regarding Marshaling Data Structure and IntPtr!"
- In reply to: Ken Kolda: "Re: little more help on remoting?"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 13 Aug 2004 03:39:03 -0700
Ken - thanks. Please see inline
>
> "Patty O'Dors" <PattyODors@discussions.microsoft.com> wrote in message
> news:F6314DC8-A371-4EF9-8ED9-6BB84F99B5CC@microsoft.com...
> > Hi
> > I recently asked a question on remoting and can get it to work a bit, but
> > there are a few issues that I don't understand:
> >
> > 1) i can't get it to return a different instance of the remote type every
> > time. it works, but every time it is returning the same one. I'd rather
> not
> > use a configuration file if possible, I much rather the code method (code
> is
> > below)
> >
>
> In your code below, you have effectively created a singleton (the
> RemoteParent instance on which you called RemotingServices.Marshal()) which
> acts as a factory for the RemoteChild object. As a result, when your clients
> call "new RemoteParent()" they all get proxies the same instance on the
> server (Guid should be the same). However, when they call HaveChild(), they
> will each get their own unique instance of the RemoteChild class (you should
> see they have different Guids). So, you've effectively already done what
> you're asking -- you've created a technique for each client to get their own
> instance of the RemoteChild object without having to register a
> client-activated type with the remoting framework.
I've now replaced that with a call to RegisterWellKnownServiceType - it
seems to be able to supply either a singleton or mutliple objects depending
on what flag I choose.
>
> > 2) are there any disadvantages to SingleCall / Singleton ? What if another
> > client makes a request and a singleton is already doing some work, what
> will
> > happen then?
> >
>
> Singletons can handle concurrent requests without a problem -- each will
> execute on its own thread. So, your singleton object needs to be
> thread-safe.
So ... what does this mean?
Do I have to protect with a mutex all modifications to the singleton's
instance data?
Should such a mutex be a static member of the class?
If I make a SingleCall object, but make some static methods, will that be
more thread safe than a singleton, or better or worse? In what way?
> A single-call object, on the other hand, only handles one call
> from one client, so thread-safety isn't as much as concern. I use singletons
> unless there is a specific need for a single-call object since I have more
> control over them (e.g. I can access the same singleton object from my
> server code as is accessed from the clients, which isn't possible with
> single-call unless your single-call objects are just forwarding the calls to
> a singleton elsewhere).
A singleton sounds good, seeing as it fires off multiple threads. I
understand why it needs to be thread-safe, but it's *how* thread safe does it
need to be, and what are the typical implications/restrictions of this
requirement?
>
> > 3) In the code below, I commented out the call to rp.HaveChild().Report()
> > and the client crashed, throwing a web exception when it ran on a
> different
> > machine. The server however ran rp.Report() ok. (rp.Report() ran fine.) Is
> > this because I haven't registered the child as a remotable type?
>
> Can you give the details of the exception (the full message and call stack)?
>
> >
> > 4) If two clients both connect to a singleton at the same time, do they
> both
> > get their own thread in the server?
>
> Yes, each request executes in its own thread on the server.
>
> Regards -
> Ken
>
>
> >
> >
> > //code in the remote object's DLL:
> >
> > public class RemoteParent : MarshalByRefObject
> > {
> > protected Guid uniqueid = Guid.NewGuid();
> > public RemoteParent(){}
> > public void Report(){Console.WriteLine("Parent: " + uniqueid.ToString());}
> > public RemoteChild HaveChild() {return new RemoteChild();}
> > }
> >
> > public class RemoteChild : MarshalByRefObject
> > {
> > protected Guid uniqueid = Guid.NewGuid();
> > public RemoteChild(){}
> > public void Report(){Console.WriteLine(" Child: " +
> uniqueid.ToString());}
> > }
> >
> > //code for the server:
> > public class ServerProcess
> > {
> > [MTAThread()]
> > public static void Main()
> > {
> >
> > HttpChannel channel = new HttpChannel(0xBEEF);
> > ChannelServices.RegisterChannel(channel);
> > ObjRef ref_rp = RemotingServices.Marshal(rp, "objRemoteParent");
> >
> > Console.WriteLine("Press enter to stop the server");
> > Console.ReadLine();
> >
> > RemotingServices.Disconnect(rp);
> > ChannelServices.UnregisterChannel(channel);
> > }
> > }
> >
> >
> > //code in the client:
> > [MTAThread()]
> > public static void Main()
> > {
> > Console.WriteLine("Please enter net address:");
> > string netaddress = Console.ReadLine(),
> > httpaddress = string.Format("http://{0}:{1}/objRemoteParent", netaddress,
> > 0xBEEF);
> > HttpChannel channel = new HttpChannel(0);
> > ChannelServices.RegisterChannel(channel);
> >
> RemotingConfiguration.RegisterWellKnownClientType(Type.GetType("remote.Remot
> eParent, remote"), httpaddress);
> > RemoteParent rp = new RemoteParent();
> > try
> > {
> > //Console.WriteLine(sc.GetServerTime().ToString("yyyy-mm-dd hh:mm:ss"));
> > rp.Report();
> > //rp.HaveChild().Report(); <<CAUSES WEB EXCEPTION...
> > //but only when run from a different machine? Fine on localhost...
> > }
> > catch (Exception ex)
> > {
> > Console.WriteLine("Exception of type: " + ex.GetType().ToString() + "
> > occurred.");
> > Console.WriteLine("Details: " + ex.Message);
> >
> > }
> > }
> >
> >
> >
>
>
>
- Next message: Patty O'Dors: "Re: [Newbie] What are ASP.NET and ADO.NET ?"
- Previous message: BMermuys: "Re: Regarding Marshaling Data Structure and IntPtr!"
- In reply to: Ken Kolda: "Re: little more help on remoting?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|