Reputation: 855
We need to send some data from my .net WinForm application to electron application. As both applications are independent we need to open some TCP port in nodejs project and send data on same port from my .net app but here I am stuck between how I can send the data from my .net app.
Can someone please provide an example or documentation which would help me to resolve my issue.
I tried to achieve it using node-ipc package but no luck.
Upvotes: 1
Views: 2118
Reputation: 21
I had the same roadblock in my application.
You could use the mechanism of Inter process communication, use socket.io and create a socket to act as a communication link between the two process.
You'll have to create a socket listener in your your electron app, the following snippet worked for me
var serverSocket = require('net');
var webFrame = require('electron').webFrame;
function createSocketListener(PORT, HOST) {
serverSocket.createServer(function (socket) {
var buffer = "";
console.log('CONNECTED: ' + socket.remoteAddress + ':' + socket.remotePort);
socket.on('data', function (data) {
buffer = data;
});
socket.on('close', function (data) {
// closed connection
console.log('DATA : ' + buffer);
});
}).listen(PORT, HOST);
}
You can then create your custom protocol and send the data from your .net application to the electron application by connecting to the same socket.
You can look into the following link for further control and optimization. https://electronjs.org/docs/api/ipc-main
Upvotes: 1