Settings

Theme

Show HN: ElectronCGI – Cross Platform .Net Core GUIs with Electron

4 points by rdfi 7 years ago · 2 comments · 1 min read


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/)
die_fault_user 7 years ago

Very interesting - could this be used with another back end other than .net?

  • rdfiOP 7 years ago

    Currently the only implementation available is for .Net through the ElectronCgi.DotNet nuget package, but there's no reason for this not to work with other languages/runtimes (it relies on stdin/stdout that is available in all processes).

    Did you have a particular language/runtime in mind?

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection