I am trying to establish IPC between Node and Console app written in .NET 6 on macOS. It launches the Application, however, cannot perform the IPC.
Once Console app is launched, I can write to console and that is received correctly, however, whatever is sent by Node App is not received by Console App.
Following is the code
Node
var spawn = require('child_process').spawn;
var ipc = spawn('open',['./console-app-demo']);
ipc.stdin.setEncoding('utf8');
ipc.stderr.on('data', function(data) {process.stdout.write(data.toString()};
ipc.stdout.on('data', function(data) {process.stdout.write(data.toString()};
ipc.stdin.write(JSON.stringify({message: 'hello world'}));
C#
static void Main(string[] args)
{
Console.WriteLine("hello world from .Net 6");
Thread t = new Thread(TestIPC);
t.Start();
Console.ReadLine();
}
static void TestIPC()
{
var input = Console.OpenStandardInput();
var buffer = new byte[512];
int length;
while(input.CanRead && (length = input.Read(buffer, 0, buffer.Length))
{
var payload = new byte[length];
Buffer.BlockCopy(buffer, 0, payload, length);
Console.Write("received: " + Encoding.UTF8.GetString(payload));
Console.Out.Flush();
}
}
I could enter the Console that is opened and write message that gets printed back as received by .Net Application. Node script resides in the same folder as the console-app-demo.
Will appreciate any suggestion.