IPC Remoting

Example of using IPC remoting to send messages between processes: The code needs implementation of server availability checking to see if the server application is present and listening for messages (else the code crashes)

Project: IPC_SharedInterfaces Class: ICommunicationService

Public Interface ICommunicationService
Sub SaySomething(ByVal text As String)
End Interface

Project: IPC_Server Class: CommunicationService

Public Class CommunicationService
Inherits MarshalByRefObject
Implements IPC_SharedInterfaces.ICommunicationService
Public Sub SaySomething(ByVal text As String) Implements IPC_SharedInterfaces.ICommunicationService.SaySomething
MsgBox(text)
End Sub
End Class

Class: Form1

Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Ipc
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim ipcCh As IpcChannel
ipcCh = New IpcChannel("MojProgramcic")
ChannelServices.RegisterChannel(ipcCh, False) RemotingConfiguration.RegisterWellKnownServiceType( GetType(CommunicationService), "MojURI", WellKnownObjectMode.Singleton)
End Sub
End Class

References: IPC_SharedInterfaces, System.runtime.Remoting

Project: IPC_Client Class: Form1

Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Ipc
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim ipcCh As New IpcChannel("MojKlijent")
ChannelServices.RegisterChannel(ipcCh, False) Dim obj As IPC_SharedInterfaces.ICommunicationService = DirectCast(Activator.GetObject(GetType(IPC_SharedInterfaces.ICommunicationService), "ipc://MojProgramcic/MojURI"), IPC_SharedInterfaces.ICommunicationService)
Try
obj.SaySomething(Now.TimeOfDay.ToString)
Catch err As System.Runtime.Remoting.ServerException
MsgBox(err)
End Try
ChannelServices.UnregisterChannel(ipcCh)
End Sub
End Class

References: IPC_SharedInterfaces, System.runtime.Remoting