PC Review


Reply
Thread Tools Rate Thread

Communication via IPC

 
 
=?Utf-8?B?QnJpYW4=?=
Guest
Posts: n/a
 
      8th Nov 2005
Hello,

I've been reading up on IPC and looking at sample code, and I can't seem to
figure out how to actually accomplish communication from a client to a
server. I understand the concept of a server hosting a dll which contains a
method that the client can call. However, how can the server also obtain a
reference to the same object? I want the client to be able to send a message
that makes it to where the server can use it.

To clarify my question, the examples I've seen so far have been like this:

Server creates a channel exposing Class A.
Class A contains a handy-dandy method that can multiply two ints.
Client creates a channel to be able to instantiate a new Class A object and
call its methods.

But how does Client get a message all the way back to Server?

I tried creating a client channel in the server itself, but I can't make
that work. I get an exception saying that there is already a registered
object for that channel. I also tried creating an instance of Class A in the
server, but it was a completely separate object that did not see messages
that the client put into it.

To give some context, I have a Windows service that needs to be controlled
via a Windows Forms app. As I understand it, to get messages to the Windows
service, I would create a channel there and have the Forms app be the client.
But how do I actually retrieve the messages from within the service?

Apparently IPC is the way to go for on-box communication, but I haven't seen
any examples showing how to get a client and server to exchange actual
messages. Please help!

Brian
 
Reply With Quote
 
 
 
 
Richard Grimes
Guest
Posts: n/a
 
      8th Nov 2005
Brian wrote:
> To clarify my question, the examples I've seen so far have been like
> this:
>
> Server creates a channel exposing Class A.
> Class A contains a handy-dandy method that can multiply two ints.
> Client creates a channel to be able to instantiate a new Class A
> object and call its methods.


You're talking about .NET Remoting?

> But how does Client get a message all the way back to Server?


Well, once the client has instantiated an instance of Class A it has a
proxy to that object. Then all the client does is call a method on the
object proxy.

> I tried creating a client channel in the server itself, but I can't
> make that work. I get an exception saying that there is already a
> registered object for that channel. I also tried creating an instance
> of Class A in the server, but it was a completely separate object
> that did not see messages that the client put into it.


Do you want the server to call methods on the client? If so, then you
need to register a channel on the client to do that. You don't need to
do anything on the server, if the callback to the client is through a
delegate to a client method, or if the client creates a
MarshalByRefObject object and passes that to the server.

> To give some context, I have a Windows service that needs to be
> controlled via a Windows Forms app. As I understand it, to get
> messages to the Windows service, I would create a channel there and
> have the Forms app be the client. But how do I actually retrieve the
> messages from within the service?


I think I understand what you mean. In the service you register a class
to be activated remotely. The client activates an object of that class
and calls its methods. You want these methods to talk to the service,
and want to know how this remoted object talks to the service object
even though they are in the same process.

The problem is that remoting uses threads in the process threadpool, so
the thread that will handle client calls will not be the same as the
thread that runs the service object, so whatever you do, you have to
take inter-thread communication into account. A ReaderWriterLock would
help here.

It all depends on how you are managing state. If the service state is in
a database, then your remoted object can simply access that state
through a database connection.

If the state is maintained in memory, then you will have to take steps
to protect it. I would create a class that has a static member that
gives access to this state. The service object can initialise this
static member when the service starts. The methods of this class needs
to be protected by a ReaderWriterLock so that when one client is writing
data (ie passing data to the service) no other client nor the service
can write data; if no one is trying to write then there will be no lock.

Richard
--
http://www.grimes.demon.co.uk/workshops/fusionWS.htm
http://www.grimes.demon.co.uk/workshops/securityWS.htm


 
Reply With Quote
 
=?Utf-8?B?QnJpYW4=?=
Guest
Posts: n/a
 
      8th Nov 2005
Richard,

Thanks. Having static members in the class allows me to retrieve values set
by the client in my server code. That did the trick.

But is this really the way

"Richard Grimes" wrote:

> Brian wrote:
> > To clarify my question, the examples I've seen so far have been like
> > this:
> >
> > Server creates a channel exposing Class A.
> > Class A contains a handy-dandy method that can multiply two ints.
> > Client creates a channel to be able to instantiate a new Class A
> > object and call its methods.

>
> You're talking about .NET Remoting?
>
> > But how does Client get a message all the way back to Server?

>
> Well, once the client has instantiated an instance of Class A it has a
> proxy to that object. Then all the client does is call a method on the
> object proxy.
>
> > I tried creating a client channel in the server itself, but I can't
> > make that work. I get an exception saying that there is already a
> > registered object for that channel. I also tried creating an instance
> > of Class A in the server, but it was a completely separate object
> > that did not see messages that the client put into it.

>
> Do you want the server to call methods on the client? If so, then you
> need to register a channel on the client to do that. You don't need to
> do anything on the server, if the callback to the client is through a
> delegate to a client method, or if the client creates a
> MarshalByRefObject object and passes that to the server.
>
> > To give some context, I have a Windows service that needs to be
> > controlled via a Windows Forms app. As I understand it, to get
> > messages to the Windows service, I would create a channel there and
> > have the Forms app be the client. But how do I actually retrieve the
> > messages from within the service?

>
> I think I understand what you mean. In the service you register a class
> to be activated remotely. The client activates an object of that class
> and calls its methods. You want these methods to talk to the service,
> and want to know how this remoted object talks to the service object
> even though they are in the same process.
>
> The problem is that remoting uses threads in the process threadpool, so
> the thread that will handle client calls will not be the same as the
> thread that runs the service object, so whatever you do, you have to
> take inter-thread communication into account. A ReaderWriterLock would
> help here.
>
> It all depends on how you are managing state. If the service state is in
> a database, then your remoted object can simply access that state
> through a database connection.
>
> If the state is maintained in memory, then you will have to take steps
> to protect it. I would create a class that has a static member that
> gives access to this state. The service object can initialise this
> static member when the service starts. The methods of this class needs
> to be protected by a ReaderWriterLock so that when one client is writing
> data (ie passing data to the service) no other client nor the service
> can write data; if no one is trying to write then there will be no lock.
>
> Richard
> --
> http://www.grimes.demon.co.uk/workshops/fusionWS.htm
> http://www.grimes.demon.co.uk/workshops/securityWS.htm
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
No Communication Rhoni Windows Vista Mail 1 2nd Aug 2008 04:51 PM
InterProcess Communication, .Net to C++ communication batista Microsoft Dot NET 4 16th Oct 2006 07:21 AM
InterProcess Communication, .Net to C++ communication batista Microsoft C# .NET 1 12th Oct 2006 02:09 PM
Communication Lars Microsoft Windows 2000 DNS 2 21st Oct 2004 04:42 AM
W2K-NT communication slower than NT-NT communication peter.somers.ps@bigfoot.com Microsoft Windows 2000 Networking 0 1st Nov 2003 02:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:56 AM.