[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

microsoft.public.dotnet.framework.remoting

How to access published singleton object from the host itself?

Willliam

6/30/2004 1:38:00 AM

I'm publishing a singleton object on a windows-forms based host .exe program, but also want to monitor its state from this host .exe, basically displaying some internal state member variables every 5 mins in a textbox.

What's the best approach to take for this scenario?

It's actually a kind of interprocess communication, with one process (the host) publishing an object, whereas other processes can access it remotely. I just want to understand how the hosting process can access this object locally?

Thanks,
William
6 Answers

Sunny

6/30/2004 2:55:00 PM

0

Hi William,

Do not expose the singleton with WellKnown... or config files. Just do
this (pseudocode):

CreateChannel();
RegisterChannel();

MySingleton myObj = new MySingleton();

RemotingServices.Marshal(myObj, "<uri for the clients to use>", typeof
(MySingleton));


now, locally you can access your object using the myObj variable, and
the clients will connect as usual.

Hope that helps
Sunny


In article <8F085973-260A-4F2C-A8E4-D4967ED3D8F0@microsoft.com>,
Willliam@discussions.microsoft.com says...
> I''m publishing a singleton object on a windows-forms based host .exe program, but also want to monitor its state from this host .exe, basically displaying some internal state member variables every 5 mins in a textbox.
>
> What''s the best approach to take for this scenario?
>
> It''s actually a kind of interprocess communication, with one process (the host) publishing an object, whereas other processes can access it remotely. I just want to understand how the hosting process can access this object locally?
>
> Thanks,
> William
>

Ken Kolda

6/30/2004 3:07:00 PM

0

In this case, you just need to create a static singleton and then remote it
yourself using RemotingServices.Marshal() instead of
RemotingConfiguration.RegisterWellKnownServiceType(). For example:

public class MySingletonClass : MarshalByRefObject
{
public static readonly MySingletonClass RemotedInstance = new
MySingletonClass();
}

public class RemotingServer
{
public RemotingServer()
{
// Setup your channel, etc.
TcpChannel tcp = new TcpChannel(2002);
// ... etc.

// Marshal the object to make it available via remoting
RemotingServices.Marshal(MySingletonClass.RemotedInstance,
"MySingletonClass.rem");
}
}

Within the server, just refer to the singleton using the static reference --
you''ll get the same instance as those accessing it via remoting.

Ken


"Willliam" <Willliam@discussions.microsoft.com> wrote in message
news:8F085973-260A-4F2C-A8E4-D4967ED3D8F0@microsoft.com...
> I''m publishing a singleton object on a windows-forms based host .exe
program, but also want to monitor its state from this host .exe, basically
displaying some internal state member variables every 5 mins in a textbox.
>
> What''s the best approach to take for this scenario?
>
> It''s actually a kind of interprocess communication, with one process (the
host) publishing an object, whereas other processes can access it remotely.
I just want to understand how the hosting process can access this object
locally?
>
> Thanks,
> William


Willliam

7/1/2004 1:33:00 AM

0

Hi Sunny and Ken,

Many thanks for your detailed suggestion, it works!

William

Sunny

7/7/2004 5:37:00 PM

0

Hi,
you can run your host as a windows service. thus it will be as long
running as the machine is on. In the OnStar method of the service just
create the remoting object and expose it for remoting as show in the
response to the OP. You can start all your threads and socket listeners
there as well.

Sunny


In article <etk$gfDZEHA.3716@TK2MSFTNGP11.phx.gbl>,
dotnet@clumsybiker.com says...
> William,
>
> I was interested to read your original request for information - publishing a singleton from a long-running host .exe is exactly what I wish to achieve:
>
> The host.exe is going to be responsible for receiving and queueing messages coming in over TCP/IP sockets, using multi-threading, and then a remote client is going to connect (via remoting) to the .exe to request messages from the queues.
>
> I''m having a hard time finding tutorials on how to do the bit you described - having the long-running .exe being the app which is connected to via remoting.
>
> Can you recommend a source for info on this subject?
>
> Best Regards,
> Glen (ClumsyBiker)
>
> >Hi Sunny and Ken,
> >
> > Many thanks for your detailed suggestion, it works!
> >
> > William
> >
>
> ___
> Newsgroups brought to you courtesy of www.dotnetjohn.com
>

ClumsyBiker

7/8/2004 3:00:00 PM

0

OK, I think I''m getting this:

but if the long-running exe (or service) is the app that creates and manages the sockets, listeners and queues, and the client apps are all connecting to Remotable Classes, then my client apps can call methods contained in the Remotable Classes, but they still can''t call public methods and functions contained within the host .exe itself?

e.g. my .exe has a function like ReadMsgFromQueue(byval QNum as integer). If the client connects to <RemotableClassA>, it can see the methods of <RemotableClassA>, but it can''t see the function ReadMsgFromQueue?

Either I still haven''t got a handle on remoting, or what I want isn''t possible - for the public methods and functions of the host .exe to be available to be called, just like traditional ActiveX EXEs under VB6.0

Or perhaps there is a further way in which server-created instances of the Remotable Class can converse with public functions contained within the host .exe?

>Hi,
> you can run your host as a windows service. thus it will be as long
> running as the machine is on. In the OnStar method of the service just
> create the remoting object and expose it for remoting as show in the
> response to the OP. You can start all your threads and socket listeners
> there as well.
>
> Sunny
>
>
> In article <etk$gfDZEHA.3716@TK2MSFTNGP11.phx.gbl>,
> dotnet@clumsybiker.com says...
> > William,
> >
> > I was interested to read your original request for information - publishing a singleton from a long-running host .exe is exactly what I wish to achieve:
> >
> > The host.exe is going to be responsible for receiving and queueing messages coming in over TCP/IP sockets, using multi-threading, and then a remote client is going to connect (via remoting) to the .exe to request messages from the queues.
> >
> > I''m having a hard time finding tutorials on how to do the bit you described - having the long-running .exe being the app which is connected to via remoting.
> >
> > Can you recommend a source for info on this subject?
> >
> > Best Regards,
> > Glen (ClumsyBiker)
> >
> > >Hi Sunny and Ken,
> > >
> > > Many thanks for your detailed suggestion, it works!
> > >
> > > William
> > >
> >
> > ___
> > Newsgroups brought to you courtesy of www.dotnetjohn.com
> >
>

___
Newsgroups brought to you courtesy of www.dotnetjohn.com

Sunny

7/8/2004 4:09:00 PM

0

I can not understand completely there. The .exe can not have a function.
A class can. You can make the class which contains ReadMsgFromQueue
remotable, and expose it to the clients. Or in your <RemotableClassA>
you can create a method ReadMsgFromQueue which in turn invokes the
original one.


Sunny


In article <#EpP4wPZEHA.3304@TK2MSFTNGP09.phx.gbl>,
dotnet@clumsybiker.com says...
> OK, I think I''m getting this:
>
> but if the long-running exe (or service) is the app that creates and manages the sockets, listeners and queues, and the client apps are all connecting to Remotable Classes, then my client apps can call methods contained in the Remotable Classes, but they still can''t call public methods and functions contained within the host .exe itself?
>
> e.g. my .exe has a function like ReadMsgFromQueue(byval QNum as integer). If the client connects to <RemotableClassA>, it can see the methods of <RemotableClassA>, but it can''t see the function ReadMsgFromQueue?
>
> Either I still haven''t got a handle on remoting, or what I want isn''t possible - for the public methods and functions of the host .exe to be available to be called, just like traditional ActiveX EXEs under VB6.0
>
> Or perhaps there is a further way in which server-created instances of the Remotable Class can converse with public functions contained within the host .exe?
>
> >Hi,
> > you can run your host as a windows service. thus it will be as long
> > running as the machine is on. In the OnStar method of the service just
> > create the remoting object and expose it for remoting as show in the
> > response to the OP. You can start all your threads and socket listeners
> > there as well.
> >
> > Sunny
> >
> >
> > In article <etk$gfDZEHA.3716@TK2MSFTNGP11.phx.gbl>,
> > dotnet@clumsybiker.com says...
> > > William,
> > >
> > > I was interested to read your original request for information - publishing a singleton from a long-running host .exe is exactly what I wish to achieve:
> > >
> > > The host.exe is going to be responsible for receiving and queueing messages coming in over TCP/IP sockets, using multi-threading, and then a remote client is going to connect (via remoting) to the .exe to request messages from the queues.
> > >
> > > I''m having a hard time finding tutorials on how to do the bit you described - having the long-running .exe being the app which is connected to via remoting.
> > >
> > > Can you recommend a source for info on this subject?
> > >
> > > Best Regards,
> > > Glen (ClumsyBiker)
> > >
> > > >Hi Sunny and Ken,
> > > >
> > > > Many thanks for your detailed suggestion, it works!
> > > >
> > > > William
> > > >
> > >
> > > ___
> > > Newsgroups brought to you courtesy of www.dotnetjohn.com
> > >
> >
>
> ___
> Newsgroups brought to you courtesy of www.dotnetjohn.com
>