title: IPC communication between .net and nodejs
body: <p>I'm having problems implementing a two way communication between a .NET and a Node.js application.</p>
  
  <p>I want them to be able to pass multiple messages back and forth between them before closing the channel, but something isn't quite working when sending messages from the Node server.</p>
  
  <p>I can send messages from the client to the server, but when sending from the server the <code>reader.ReadLine()</code> gets the data but never continues until I close the connection.</p>
  
  <p>I feel that a flush or something like that is missing, but I can't find anywhere how it should be implemented. I don't want to close and reconnect if possible.</p>
  
  <p>Node server:</p>
  
  <pre><code>const net = require("net");
  
  const server = net.createServer((stream) =&gt; {
    console.log("Server: on connection");
  
    stream.on("data", (buffer) =&gt; {
      console.log("Got data:", buffer.toString());
      stream.write("Reverse me");
    });
  
    stream.on("end", () =&gt; {
      console.log("Stream ended");
      server.close();
    });
  });
  
  server.listen("\\\\.\\pipe\\myPipe", () =&gt; {
    console.log("Listening...");
  });
  </code></pre>
  
  <p>C# client:</p>
  
  <pre><code>static void Main(string[] args)
  {
      var client = new NamedPipeClientStream("myPipe");
  
      client.Connect();
  
      StreamReader reader = new StreamReader(client);
      StreamWriter writer = new StreamWriter(client);
  
      while (true)
      {
          if (!client.IsConnected)
          {
              break;
          }
  
          var line = reader.ReadLine();
  
          writer.WriteLine(line.Reverse());
          writer.Flush();
      }
  }
  </code></pre>