• Stars
    star
    149
  • Rank 247,516 (Top 5 %)
  • Language
    C#
  • License
    Apache License 2.0
  • Created about 10 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A tiny .NET library to do inter-process communication (IPC) between different processes on the same machine.

Zeta IPC

A tiny .NET library to do inter-process communication (IPC) between different processes on the same machine.

NuGet

Get the ZetaIpc NuGet package.

Background

First trying ZeroMQ to do some very small IPC between two WinForms processes on the same machine, I failed and didn't bother to dig deeper. Instead I used the phantastic C# WebServer project and quickly assembled some small wrapper.

I intentionally implemented only simple string send and receive methods, everything else is out of scope of the library. E.g. you could use Json.NET to transfer JSON within the strings between the client and the server.

Using the server

To use the server (i.e. the "thing" that listens for incoming request and answers them), do something like:

var s = new IpcServer();
s.Start(12345); // Passing no port selects a free port automatically.

Console.WriteLine("Started server on port {0}.", s.Port);

s.ReceivedRequest += (sender, args) =>
{
    args.Response = "I've got: " + args.Request;
    args.Handled = true;
};

This starts a new background thread and continues execution.

Later, simply call

s.Stop();

to stop the server again.

Using the client

To use the client (i.e. the "thing" that can send texts to the server), do something like:

var c = new IpcClient();
c.Initialize(12345);

Console.WriteLine("Started client.");

var rep = c.Send("Hello");
Console.WriteLine("Received: " + rep);

Bi-directional usage

If you want a bi-directional communication between the server and client that can be started by both the client and the server, simply use the above code of the server on the client and the code of the client on the server (use different ports, of course).

This gives you two applications, each of them being server and client at the same time.

How to tell the port from the client to the server?

I've developed the library to start an external application from my main application. My main application acts as the client and my external application as the server.

The whole process of starting and communicating with the external application roughly follows these steps:

  1. Main application is running.
  2. User clicks a menu item, which requires to launch the external application.
  3. By calling the FreePortHelper.GetFreePort() method on the main application, a free port number is being gathered.
  4. The main application calls the external application (through a relative file path) and passes the free port number as a command line parameter to the external application.
  5. The external application reads the so passed port number from the command line and starts an instance of IpcServer on this given port.
  6. The main application waits for a few seconds and then uses an instance of IpcClient to send messages to the external application and receives messages back. If you want to wait until the server has really started and is ready, you can use an event wait handle.

Notes

More Repositories

1

ZetaResourceEditor

Free multilingual, parallel .NET resource file editing
C#
257
star
2

ZetaLongPaths

A .NET library to access files and directories with more than 260 characters length.
C#
136
star
3

dot-net-transitions

A library for animated UI transitions for .NET
C#
98
star
4

ZetaHtmlEditControl

A small wrapper class around the Windows Forms 2.0 WebBrowser control.
C#
76
star
5

ZetaProducerHtmlCompressor

A .NET port of Googleโ€™s HtmlCompressor library to minify HTML source code.
HTML
31
star
6

SimpleBackup

Windows Explorer Context Menu extension to backup and restore folders to temporary storage
C#
11
star
7

aspnetserve

A free and open source ASP.NET 2.0/3.x web server.
JavaScript
4
star
8

ZetaShortPaths

A .NET Standard library with all the goodies from the Zeta Long Paths library to work with files and folders for paths with less than 260 characters.
C#
3
star
9

IntelligentInclude

Small Windows command line tool that mimics the Persistent Includes syntax of the BBEdit editor to include files into other files while preserving the include directive itself.
C#
2
star
10

ExitCodeGenerator

Console application to sleep for a given amount of milliseconds and then return a given exit code.
C#
2
star
11

about-me

Informationen รผber Uwe Keim.
2
star
12

atoms

Sources of my computer game "Atoms" back from 1995
Pascal
2
star
13

example-net-core-rendered-views-ajax

Example ASP.NET Core MVC 6 project that renders nested Partial Views dynamically via AJAX
JavaScript
1
star
14

console-flasher

A command line tool to flash the window via FlashConsoleEx WinAPI call
C#
1
star