NamedPipeServerStream serverPipe = new NamedPipeServerStream("testpipe"); byte[] data = Encoding.ASCII.GetBytes("Hello from server!"); serverPipe.BeginWrite(data, 0, data.Length, null, null); int bytesWritten = serverPipe.EndWrite();
using (NamedPipeServerStream pipeServer = new NamedPipeServerStream("testpipe")) { pipeServer.WaitForConnection(); byte[] data = new byte[1024]; int bytesRead = pipeServer.Read(data, 0, data.Length); pipeServer.BeginWrite(data, 0, bytesRead, null, null); int bytesWritten = pipeServer.EndWrite(); }In this example, we create a named pipe server stream with the name "testpipe". We wait for a client to connect to the pipe using the WaitForConnection method. Then we read some data from the pipe using the Read method. Finally, we write the same data back to the client using the BeginWrite and EndWrite methods. Package Library: System.IO.Pipes.