If the need is just to do a cross process communication within the box, it'd be bit heavy to use frameworks such as WCF as it comes with a learning curve and complex setup. However home grown solutions such as messaged based implementation suffer from flexibility and heavy maintenance.
The simpleIPC framework tries to strike right balance with the interface based programming coupled with zero setup.
IPC Overview
A lightweight Inter Process Communication (IPC) across process within the same PC in .Net can be implemented using named event object or Window kernel object and shared memory.
- Interface based programming
- Duplex communication support
- Servers are identified by a unique string to which clients can generate a proxy to communicate. Some of the features:
- Servers/ Clients generate Stubs/ Proxy based on an interface for communication using reflection.
- As the proxy is based on the RealProxy object, intellisense is also supported in the Visual Studio IDE editor. Easy to debug, just a single file of code.
- To access a managed server from an unmanaged client, reversePinvoke can be used.
As shown in the diagram above. IPC consists of a Client, Proxy, Stub and Server as described below
- Client uses proxy based on RealProxy to make API call
- Proxy serializes the input data using binary formatter to shared memory and signals stub
- Stub deserializes the input data using binary formatter from shared memory and makes the call on the server using reflection
- Stub serializes the results to shared memory and signals Proxy
- Proxy deserializes the results from shared memory and returns it to the client
Implementation
Comes in two flavors windows kernel object based or named event kernel object based.
Windows based uses a window kernel object for implementing the server
- A Named event object based container supports only one server
- A named event object based server can work across window stations
Example
The interface ICallInterface shown below is implemented by the server and ICallbackInterface is implemented by the client.Server Process
Simple IPC Server name for ICallback : winserver
Client Process
Simple IPC server name for ICallbackInterface : winclient
Server Process
Simple IPC Server name for ICallback : namederver
Server process starts
client process starts
Client:
creates proxy for server
calls register() on server using proxy
Server:
executes method register()
server returns success with Ticket #100
Client:
results are received from proxy : success, Ticket:100
Server:
creates proxy for client implementing callback interface
calls update() method on the proxy
.
Client:
executes update() method
Source and Binaries can be found here.