(1)发送请求的的客户端
1 NamedPipeClientStream clientStream = new NamedPipeClientStream(".", "clientpipe", PipeDirection.InOut, PipeOptions.None, System.Security.Principal.TokenImpersonationLevel.Impersonation);//设定请求的管道名称,以便server管道进行接收 2 clientStream.Connect(); 3 using (StreamWriter sw = new StreamWriter(clientStream)) 4 { 5 sw.Write(textBox1.Text); 6 }
(2)接收受进行处理的服务端
1 NamedPipeServerStream serverstream = new NamedPipeServerStream("clientpipe", PipeDirection.InOut,2);//接收指定名称的client管道的数据 2 serverstream.WaitForConnection(); 3 using (StreamReader sr = new StreamReader(serverstream)) 4 { 5 textBox1.Text = sr.ReadToEnd(); 6 }
完!