|
|
|
Show HN: ElectronCGI – Cross Platform .Net Core GUIs with Electron
|
|
4 points
by rdfi
2674 days ago
|
|
ElectronCGI is a library that enables making requests from a NodeJs application that are served by a .Net application. It uses the standard in/out streams for communication. To use it install the electron-cgi npm package on you node application and the ElectronCgi.DotNet nuget package on your .Net console app. Here's an example: In NodeJs/Electron: const { ConnectionBuilder } = require('electron-cgi');
const connection = new ConnectionBuilder()
.connectTo('dotnet', 'run', '--project', 'DotNetConsoleProjectWithElectronCgiDotNetNugetPackage')
.build();
connection.onDisconnect = () => {
console.log('Lost connection to the .Net process');
};
connection.send('greeting', 'John', theGreeting => {
console.log(theGreeting); // will print "Hello John!"
});
connection.close();
And in the .Net Console Application: using ElectronCgi.DotNet;
//...
static void Main(string[] args)
{
var connection = new ConnectionBuilder()
.WithLogging()
.Build();
// expects a request named "greeting" with a string argument and returns a string
connection.On<string, string>("greeting", name =>
{
return $"Hello {name}!";
});
// wait for incoming requests
connection.Listen();
}
[Blog post with extra information about ElectronCGI](https://www.blinkingcaret.com/2019/02/27/electron-cgi/) |
|