Start connection from .net to node, instead of node to .net
asucls opened this issue · 5 comments
Provide a way to start the connection from .Net file to Node/electron file. My use case is opening Electron app on Excel Add in's button click
If the goal is to just open the electron app then you can do that with System.Diagnostics
's Process.Start
: https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.start?view=net-6.0
Would this work for you?
No, the goal is not just to open the electron app, but instead to maintain an active connection between the two and also communicate through Stdin, Stdout, and Stderr in the form of JSON strings
I haven't implemented that. It should not be a big amount of work, however I probably won't be able to do it soon. I would gladly help if anyone is interested in giving it a go
Could you please provide some advice on how to proceed with this?
Sure. The way electron cgi works is by taking advantage of the stdin and stdout streams.
When you call Connection.Listen in .NET what's happening is that you are setting up the connection with .NET's own stdin and stdout streams: https://github.com/ruidfigueiredo/electron-cgi-dotnet/blob/master/ElectronCgi.DotNet/Connection.cs#L216
What needs to happen instead is that we'd need to add a counterpart of js' connection builder's build method to the Connection in .NET that starts the node process (using System.Diagnostics.Process), captures its stdin and stdout streams and uses those instead.
You also need to have the node process process register handlers for its stdin and stdout (process.stdin and process.stdout) when it starts, this is the counterpart to .NET's Connection.Listen. If you look at the Connection class in node here you can see that it expects an outStream and an inStream. In this case the outStream is process.stdout and the inStream is process.stdin.
This blog post might also help understand how electron-cgi work and might be useful to read before attempting this: https://www.blinkingcaret.com/2020/04/09/the-story-of-how-i-created-a-way-to-port-windows-apps-to-linux/