The XDMessaging library provides an easy-to-use, zero configuration solution to inter-process communication for .NET applications. It provides a simple API for broadcasting and receiving messages across application domain, process, and even network boundaries.
The library allows the use of user-defined pseudo channels through which messages may be sent and received. Any application can send a message to any channel, but it must register as a listener with the channel in order to receive. In this way developers can quickly and programmatically devise how their applications will communicate with each other best to work in harmony.
The messages may optionally be propagated to other processes over a network automatically.
Install the library using Nuget.
PM> Install-Package XDMessaging
The XDMessaging library offers some advantages over other IPC technologies like WCF, .Net Remoting, Sockets, NamedPipes and MailSlots. To begin with the library does not require a server-client relationship as there is no physical connection between processes.
With XDMessaging messages can be broadcast by multiple applications and instantly received by multiple listeners in a disconnected fashion. It's also worth noting that most of the existing IPC implementations require the opening of specific ports and somewhat painful configuration of settings to make work. With XDMessaging there is no configuration, the API determines where messages are sent, and which messages are received using pseudo channels.
Network propagation is a feature of the library that allows messages to leverage
Compatibility modes, whilst additionally distributing messages to a remote server.
RemoteNetwork mode is used under the hood to transfer messages to disconnected servers, and messages are rebroadcast by a slave
IXDListener instance using the original transport mode. If the slave instance terminates for any reason, then another listener instance will automatically take it’s place.
Using the Library
To use the library, create an instance of a
IXDBroadcaster and use this to send a message to a named channel. You can then create an instance of
IXDListener to receive messages on a particular channel. The channels are arbitrary strings chosen to represent a channel, and are not case sensitive.
Before creating the broadcaster and listener instances you must first decide which transport mode you want to use for the library. There are 3 modes as follows and each has advantages over the other. Modes are abstracted from their specific implementations for extensibility, and loosely coupled. In order to use one of the modes the appropriate assembly must be referenced in the project in addition to
- Compatibility: The default implementation uses file based IO to broadcast messages via a shared directory. A
FileSystemWatcheris used within listener classes to monitor changes and trigger the
MessageReceivedevent containing the broadcast message. This mode can be used in Windows Services, console applications, and Windows Forms based applications. Channels are created as separate directories on the file system for each channel. The temporary directories should be accessible by all processes, and there should be no need for manual configuration. To use this implementation add a reference to
XDMessaging.Transport.IOStreamin your project.
- HighPerformanceUI: The default implementation uses the
WM_COPYDATAWindows Message to copy data between applications. The broadcaster implementation sends the Windows Messages directly to a hidden window on the listener instance, which dispatches the
MessageReceivedevent with the copied data. Channels are created by adding/removing Windows properties. This offers the most performant solution for Windows Forms based applications, but does not work for Windows Services, Console apps, or other applications without a message pump. To use this implementation add a reference to
XDMessaging.Transport.WindowsMessagingin your project.
- RemoteNetwork: By default this uses
Amazon Web Servicesto implement a subscriber/publisher implementation for broadcasting messages over a network and interprocess. There may be associated costs involved in using this mode, and you will need to supply valid Amazon account credentials. This mode is used internally to send messages from other transport modes over the network when using network propagation mode. To use this implementation add a reference to
XDMessaging.Transport.Amazonin your project.
Note: Messages broadcast using a particular mode can only be read by applications using a listener in the same mode. For example,
Compatibility listeners cannot read messages broadcast in the
HighPerformanceUI mode. It is possible to broadcast in several modes at the same time, see documentation for further details.
See the included sample applications for more information on using the library in Windows Forms applications or within a Windows Service.