Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.IO.Pipes;
- class PipeServer
- {
- static void Main()
- {
- using (NamedPipeServerStream pipeServer =
- new NamedPipeServerStream("testpipe", PipeDirection.In))
- {
- Console.WriteLine("NamedPipeServerStream object created.");
- // Wait for a client to connect
- Console.Write("Waiting for client connection...");
- pipeServer.WaitForConnection();
- Console.WriteLine("Client connected.");
- try
- {
- using (StreamReader sr = new StreamReader(pipeServer))
- {
- // Display the read text to the console
- string temp;
- while ((temp = sr.ReadLine()) != null)
- {
- Console.WriteLine("Received from server: {0}", temp);
- }
- }
- }
- // Catch the IOException that is raised if the pipe is broken
- // or disconnected.
- catch (IOException e)
- {
- Console.WriteLine("ERROR: {0}", e.Message);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement