Two-way communication using IPC

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 access Class A.

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.

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


Answer this question

Two-way communication using IPC

  • Mr Bongo

    spend a month sharping. . . you'll never go back.

  • Rocy

    This is a great sample. Unfortunately its a console app. What if the server is a winform app and a control on the form is to display the text the client sent Any direction on this solution would be greatly appreciated.

    Thanks,

    Rick


  • MaximeR

    Not getting this to work for IPC type - how does the server calll the client Events
  • Ruel C

    I am trying to get two-way communication working with IPC. I have successfuly configured a service channel and a client channel and that seems to be allowing me to use remote events, access to object hosted by service etc. Only caveat is that my service needs to access the object that it hosts. So, I try to open up a channel from the service back up on itself and that's where I get a "The channel 'ipc' is already registered." error. The weird thing is that I have this whole set-up (service hosting an object + remoting back on itself + client channel accessing the hosted object) working fine with a config based client channel and programmatically configured service channels.

    As weird as it may sound i have checked and double checked, my three configurations and they seem to emulate what was in code. There is a very good reason for switching to configs (being able to specify parameters without code modifications + being able to specify richer variety of parameters).

    Any help would be greatly appreciated. Thanks.

    Here are all my configs:

    Service hosting remoted object:
    <system.runtime.remoting>
    <application name="Service.rem">
    <lifetime leaseTime="20D" sponsorshipTimeout="1H" renewOnCallTime="1D" leaseManagerPollTime="1H" />
    <service>
    <wellknown mode="Singleton" type="hostedObject, hostedObject.dll" objectUri="Service.rem"/>
    </service>
    <channels>
    <channel ref="ipc" portName="ServiceName" secure="true" impersonate="true" authorizedGroup="Everyone" >
    <serverProviders>
    <formatter ref="binary" typeFilterLevel="Full" />
    </serverProviders>
    </channel>
    </channels>
    </application>
    </system.runtime.remoting>

    Client channel:
    <system.runtime.remoting>
    <application>
    <lifetime leaseTime="20D" sponsorshipTimeout="1H" renewOnCallTime="1D" leaseManagerPollTime="1H" />
    <client>
    <wellknown type="hostedObject, hostedObject.dll" url="ipc:/ServiceName/Service.rem"/>
    </client>
    <channels>
    <channel ref="ipc" portName="Client" secure="true" tokenImpersonationLevel="impersonation" authorizedGroup="Everyone" >
    </channel>
    </channels>
    </application>
    </system.runtime.remoting>

    Service opening a channel back up on itself:
    <system.runtime.remoting>
    <application>
    <lifetime leaseTime="20D" sponsorshipTimeout="1H" renewOnCallTime="1D" leaseManagerPollTime="1H" />
    <client>
    <wellknown type="hostedObject, hostedObject.dll" url="ipc://ServiceName/Service.rem"/>
    </client>
    <channels>
    <channel ref="ipc" portName="Service.Remote" secure="true" tokenImpersonationLevel="impersonation" authorizedGroup="Everyone">
    </channel>
    </channels>
    </application>
    </system.runtime.remoting>

  • Shi Bai

    may be that I don't understand, but, relatively to the sample: HOW can the objected activated by the client to access the same istance of a public (non static) object in the server


  • varunsagii

    Perfect. Thank you. I'm sorry I cant share your view of VB. :)


  • CalvinH

    sicily_doc,

    If you are using Client-Activated Objects then each client gets it's own instance of the class running in the server AppDomain. The client proxy internaly stores the url of the server side object that it's communicating with.

    If you are using Server-Activated Objects you can have per-call instancing (A new instance is created for each incoming method call on the server) or you can have singleton instancing where there is a well-known URL pointing to the server. In the singleton case, the remoting infrastructure determines which server instance to marshal your messages to based on the URI that you use to create your client proxy.

    Is this what you were asking about

    -- Hoop [MSFT]



  • Phoenixheart

    mmmh about yes! I thinked to something a little different but this explanation is sufficient, I reach my goal by using the singleton activation and activating the object that the server expose both in clients and server instance.

    Now I have some problem within delgate due to security issues on deserialization... but this may will be another question!

    Thank you,

    Marco.


  • Chapel Presson

    here is a vb example.

    uses a single call, but the approach is the same. . . need to invoke a delegate

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=184240&SiteID=1



  • Robert Arthur

    Brian, if you're still running into trouble, check out our IpcChannel sample on MSDN: http://msdn2.microsoft.com/library/xcs3s8f3.aspx. The sample shows how to write a simple client and server with request-reply IPC communication.

    Cheers,

    JJustice [MSFT]


  • Codeine

    If anyone else is struggling with this same problem, here's the only solution I've discovered so far. Create a class with static members exposed in methods or properties. The server and client will each have to create their own instance of the class, but the static members will be shared between them, allowing for a rudimentary form of communication.

    This doesn't seem like the ideal solution, but I haven't seen any better way of doing it as of yet.

    Brian

  • CHOPSAW

    ...Solved too!

    on the server side simply set the typeFilterLevel to "Full" and all works fine! wow!

    a bit surprised for simpleness!

    <channels>

    <channel ref="tcp" port="6699">

    <serverProviders>

    <formatter ref="binary" typeFilterLevel="Full" />

    </serverProviders>

    </channel>

    </channels>


  • Two-way communication using IPC