Skip to content

Simple, super fast, typed and event driven style inter-process communication .Net library (on the same machine)

License

Notifications You must be signed in to change notification settings

plepilov/fast-ipc

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HeadBanner Build status

Fast IPC

Fast IPC is an open source .Net library that supports typed messages and brings inter-process communication at a higher level for better usability. It includes:

  • Inter process communication layer using named pipes. It supports smart generation of pipe name in case of parent/child processes. Other means of communication are going to be supported in the near future
  • Super fast serialization using protobuf
  • Typed event driven syntax using internally .Net built-in event capability and exposing simple api such as Subscribe and Publish

Get started

To make two processes communicate, all you need is to create an IPC bus in each process, then listen/publish on that bus, as follows:

Define your messages: All messages only need to inherit from Message and be a ProtoContract as follows:

[ProtoContract]
public class Ping : Message { }

[ProtoContract]
public class Pong : Message { }

ProcessA: One process has to be described as In (see pipe name declaration)

static void Main(string[] args) {
	var pipeName = new SimpleStringPipeName(
		name: "Example", 
		side: Side.In /* Optional */);;
	var bus = new NamedPipeBus(pipeName: pipeName);
	new ProcessAHost(bus);
	...
}
public class ProcessAHost : IHandleMessage {
	private readonly IBus _bus;

	public ProcessAsHost(IBus bus) {
		_bus = bus;
		_bus.Subscribe(this);
	}

	public void Handle(Message.Message msg) {
		HandleInternal((dynamic)msg);
	}

	private void HandleInternal(Ping msg) {
		Console.WriteLine("Received a ping, sending a pong");
		_bus.Publish(new Pong());
	}

	private void HandleInternal(Pong msg) {
		Console.WriteLine("Received a pong");
	}
}

ProcessB: The other has to be described as Out (see pipe name declaration)

static void Main(string[] args) {
	var pipeName = new SimpleStringPipeName(
		name: "Example", 
		side: Side.Out);
	var bus = new NamedPipeBus(pipeName: pipeName);
	new ProcessBHost(bus);
	...
}
public class ProcessBHost : IHandleMessage {
	private readonly IBus _bus;

	public ProcessBHost(IBus bus) {
		_bus = bus;
		_bus.Subscribe(this);
	}

	public void Handle(Message.Message msg) {
		HandleInternal((dynamic)msg);
	}

	private void HandleInternal(Ping msg) {
		Console.WriteLine("Received a ping, sending a pong");
		_bus.Publish(new Pong());
	}

	private void HandleInternal(Pong msg) {
		Console.WriteLine("Received a pong");
	}
}

And voila! ProcessA and ProcessB are communicating

Working examples are available in src folder. We also have straightforward example using the nuget package : HERE

Contribute

This project is open source. Fork then PR!

For now we are using named pipes with limitation to 2 processes communicating. We want to introduce TCP and enable multi-tier IPC.

Compatibility

  • .Net Framework >= net40
  • .Net Standard >= netstandard2.0

About

Simple, super fast, typed and event driven style inter-process communication .Net library (on the same machine)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%