This C++ Program demonstrate the use of pipes to pass a continuous stream of data between processes. It has four parts i.e.

Simple named pipe client that demonstrates the API calls needed to successfully develop a basic named pipe client application.

Overlapped Server demonstrates how to develop an advanced named pipe server that is capable of servicing 5 named pipe instances.

Simple named pipe server that demonstrates the API calls needed to successfully develop a basic named pipe server application.

Advanced named pipe server that is capable of servicing 5 named pipe instances.

Table of Contents

Client Application – Named Client Pipe

Filename: Overlap.cpp

This C++ program is a simple named pipe client that demonstrates the API calls needed to successfully develop a basic named pipe client application. When this application successfully connects to a named pipe, the message “This is a test” is written to the server.

There are four basic steps needed to implement a client:

  1. Wait for a Named Pipe instance to become available using the WaitNamedPipe() API function.
  2. Connect to the Named Pipe using the CreateFile() API function.
  3. Send data to or receive data from the server using the WriteFile() and ReadFile() API functions.
  4. Close the Named Pipe session using the CloseHandle() API functions.

Compile

Command Line Options:

None

Source Code:

Overlapped Server – Advanced Named Pipe Server

Filename: Overlap.cpp

This sample demonstrates how to develop an advanced named pipe server that is capable of servicing 5 named pipe instances. The application is an echo server where data is received from a client and echoed back to the client. All the pipe instances are serviced in the main application thread using Win32 overlapped I/O.

Compile:

cl -o overlap overlap.cpp

Command Line Options:

None

Source Code:

Simple Named Pipe Server

Filename: Server.cpp

This program is a simple named pipe server that demonstrates the API calls needed to successfully develop a basic named pipe server application. When this application receives a client connection, it reads the data from the pipe and reports the received message.

You need five basic steps to write a named pipe server:

  1. Create a named pipe instance handle using the CreateNamedPipe() API function.
  2. Listen for a client connection on a pipe instance using the ConnectNamedPipe() API function.
  3. Receive from and send data to the client using the ReadFile() and WriteFile() API functions.
  4. Close down the named pipe connection using the DisconnectNamedPipe() API function.
  5. Close the named pipe instance handle using the CloseHandle() API function.

Compile:

Command Line Options:

None

Source Code:

Thread Server – Advanced Named Pipe Server

Filename: Threads.cpp

This sample demonstrates how to develop an advanced named pipe server that is capable of servicing 5 named pipe instances. The application is an echo server where data is received from a client and echoed back to the client. All the pipe instances are serviced using threads.

Compile:

Command Line Options:

None

Source Code: