如何使用 Electron 和 Angular 连接 NamedPipe

How to connect with NamedPipe with Electron and Angular

尝试在 Angular 服务中连接命名管道并在 Electron 中构建。

我尝试了 net 套接字 类 但似乎无法正常工作,因为没有在 data 上获得 console.log

  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'));

我应该得到 console.log("connected", d.toString('utf8')))

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

没有发现您的实施有任何问题。我不确定您是否在 Socket 中写作,因为您没有在上面的代码片段中共享该段代码。

在下面尝试使用您现有的代码,相信我,您的套接字会听您的:)

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