Communication using Named Pipes (.NET)

Jawadhasan
4 min readOct 24, 2022

Introduction

Named Pipes are a mechanism for instant messaging between processes.

Following diagram shows a simple communication setup using Named Pipes:

  • The Server open a named pipe.
  • A client can listen to that pipe.
  • The client will receive message in real-time, the server send to the pipe.
  • The client must know the name of the pipe to connect to it.
  • Pipes are Byte-stream oriented.

A pipe is only useable for two processes. If you’ve a server and multiple clients, you’ll need different pipes for each client-server connection.

They also support full duplex communication and data transfer between local processes and between different machines on a network (Anonymous pipes are limited to processes which are running on the same PC). They also support client impersonation, which enables connecting processes to use their own set of permissions on remote servers.

Demo 1

A service send message via a named pipe to a client (console application) which writes it to console.

To start with I’ve created a VS solution with following projects:

  • WorkerServiceServer (the server Part of the demo — a worker application)
  • SimpleClient (the client part of demo — a console application)

You can download the source code from this git repository.

Server Implementation

Here is a very basic implementation of the server:

following is the code for the Demo1 function:

--

--

Jawadhasan

Software Solutions Team Lead | Cloud Architect | Solutions Architect