There are plenty of articles around for inter process communication, using remoting, custom windows messages and named pipes. In my .net career I think I’ve used all of them. In this article I’ll outline a technique I’ll be using that I think is quite simple.
In .net Framework 2.0, Microsoft introduced the new System.Runtime.Remoting.Channels.Ipc remoting channel , which provides one of the easiest (prior to using WCF) techniques.
In this example we have a single server process which is communicated to via client processes.
Firstly, as with all remoting it is necessary to share a type that defines the api you desire between client and server processes. One of the easiest things to do is to create an interface.
For the sake of this example, I created an assembly called “Shared Interfaces” containing an interface called “ICommunicationService”:
Public Interface ICommunicationService
Sub SaySomething(ByVal text As String)
For the Server in this example, I created a console application (it can be any sort of process).
The Server project contains two classes:
- An implementation of ICommunicationService called “CommunicationService”
- A Main that registers to CommunicationService class for acess
The CommunicationService class implements the interface and inherits from MarshalByRefObject :
Public Class CommunicationService
Public Sub SaySomething(ByVal text As String) Implements SharedInterfaces.ICommunicationService.SaySomething
Console.WriteLine(“The client said : ” & text)
The main registers the type:
Dim ipcCh As IpcChannel
ipcCh = New IpcChannel(“IPChannelName”)
GetType(CommunicationService), “SreeniRemoteObj”, _
Console.WriteLine(“Press ENTER to quit”)
The client project is written as a Winform with a textbox and a button. The button click contains this code:
Public Class Form1
Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSend.Click
Dim ipcCh As New IpcChannel(“myClient”)
Dim obj As SharedInterfaces.ICommunicationService = _
The code basically gets a reference to the remote object and invokes the “SaySomething” message, passing through a value.
As you can see, it doesn’t take much code to communicate between processes.
Further improvements to the code will involve ensuring security (making sure that only desirable client processes are calling).
Download a zip file containing the entire project for Visual Studio 2008.