Search code examples
angularelectronnamed-pipes

How to connect with NamedPipe with Electron and Angular


Trying to connect with named-pipe in Angular Service and build in Electron.

I tried net socket classes but seems like it is not working as not getting the console.log on data.

  import * as net from 'net';

  const client: net.Socket = net.connect(namedPipePath);
  client.on("data", (d: Buffer) => console.log("connected", d.toString('utf8')));
  client.on("error", (err) => console.error(err));
  client.on("end", () => console.log('disconnected from server'));

I should get the console.log("connected", d.toString('utf8')))

This is what I am getting in the console when printing client instance after net.connect(namedPipePath)


Solution

  • Didn't see anything wrong in your implementation. I am not sure if you are writing in the Socket as you didn't share that piece of code in your snippet above.

    Try below along with your existing code, and believe me your socket will listen to you :)

    public write(buffer: Buffer): void {
        if (this.client.destroyed) {
          return;
        }
        this.client.write(buffer);
      }