Coder Social home page Coder Social logo

uwekeim / zetaipc Goto Github PK

View Code? Open in Web Editor NEW
150.0 12.0 26.0 34.83 MB

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

Home Page: https://www.nuget.org/packages/ZetaIpc

License: Apache License 2.0

C# 100.00%
ipc inter-process-communication machine c-sharp json dotnet http http-server

zetaipc's Introduction

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

zetaipc's People

Contributors

cocowalla avatar dsjzazs avatar emax093 avatar maksim789456 avatar uwekeim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zetaipc's Issues

Can we use it in production?

Thank you for sharing your library, great work!
I still did not use it but it looks so simple to use and do exactly what is needed with all the complexity encapsulated!

I am very tempted to use it in production in a .net core project, but there is still no build successfully done.

1- Is the library stable for simple IPC communication under the same PC?
2- If we send a message (client.Send(some text)) and
- The server is not running what will happen?
- The server did not answer what will happens?
3- Can we expect a release version in the next weeks?

ZetaIpc 1.0.4.12 - Client does not honor timeout setting

I am using ZetaIpc between a desktop application (.Net 5) and a Windows Server (.Net 5) on the same machine. The desktop client is the "IPC Server" and the Windows Service is the "IPC Client". The idea is when a new message comes into the service, it notifies the desktop app that a new message has arrived.

The service receives messages async. and calls a Received Message Handler when a new message comes in. I write the message to a database, then kick off a client SEND to let the desktop application know a message has arrived.

If both the desktop app and service are running everything is fine. If I stop the Desktop application, the service seems to stop at the call to sending a new message notification -- even with a timeout of 100 ms. set.

applog.Debug($"BEFORE NEW MSG NOTIFY-{_msg.messageUniqueID}");
SendNewMessageNotification($"{_msg.messageUniqueID};{_msg.messageBody}");
applog.Debug($"AFTER NEW MSG NOTIFY-{_msg.messageUniqueID}");

I have this code in the location here I call out to send the message notification. It logs before and after...and you can see this is the actual file.

2022-01-14 15_06_22-CollectorService log (516 3 KB) - BareTail

You can see that when I close the desktop app, we never return from the SendNewMessageNotification method.

Here's the code where I instance the client:

//- Configure New Message Notification Client
_ipcClient = new IpcClient();
_ipcClient.Initialize(56455, 100);

...and here the code where I send the notification:

private void SendNewMessageNotification(string NewMessageData)
{
      _ipcClient.Send(NewMessageData);
      applog.Debug($"Send new message notification: {NewMessageData}");
}

-Joe

Where is the source for the included HTTPServer.dll

Including a compiled DLL as a resource without mentioning its source for verification and/or including the code from which it can be compiled independently is poor form. I would love to use this in production, but I can't trust that DLL without further details.

Looking in the DLL, it seems it originally came from Gauffin Telecom, which I assume is https://github.com/jgauffin/Griffin.WebServer. But, including info on how to compile your changes would be greatly appreciated.

As a side note, it's hard to tell since we don't know which license applies to the version of HTTPServer.dll included, but this could be a violation.

For which .NET version is this?

When I try to install it in Visual Studio I get

Error Could not install package 'ZetaIpc 1.0.0.8'. You are trying to install this package into a project that targets '.NETFramework,Version=v3.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

About UTF-8 in Chinese environment

In the process of using UTF-8 Chinese garbled code, I clone code changed a suitable version.
Encoding.UTF8.GetBytes(string.Empty) change to Encoding.Default.GetBytes(string.Empty)

License?

What is the license for this component?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.