Advertisement
Guest User

Untitled

a guest
Dec 16th, 2015
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.IO.Pipes;
  4.  
  5. class PipeServer
  6. {
  7.     static void Main()
  8.     {
  9.         using (NamedPipeServerStream pipeServer =
  10.             new NamedPipeServerStream("testpipe", PipeDirection.In))
  11.         {
  12.             Console.WriteLine("NamedPipeServerStream object created.");
  13.  
  14.             // Wait for a client to connect
  15.             Console.Write("Waiting for client connection...");
  16.             pipeServer.WaitForConnection();
  17.  
  18.             Console.WriteLine("Client connected.");
  19.             try
  20.             {
  21.                 using (StreamReader sr = new StreamReader(pipeServer))
  22.                 {
  23.                     // Display the read text to the console
  24.                     string temp;
  25.                     while ((temp = sr.ReadLine()) != null)
  26.                     {
  27.                         Console.WriteLine("Received from server: {0}", temp);
  28.                     }
  29.             }
  30.             }
  31.             // Catch the IOException that is raised if the pipe is broken
  32.             // or disconnected.
  33.             catch (IOException e)
  34.             {
  35.                 Console.WriteLine("ERROR: {0}", e.Message);
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement