c# 使用 namedpipe 通信
using System; using System.IO; using System.IO.Pipes; using System.Diagnostics; using System.Threading.Tasks; using System.Linq; using System.Threading; class PipeServer { static void Main() { StartServer(); Thread.Sleep(1000); //Client var client = new NamedPipeClientStream("PipesOfPiece"); client.Connect(); StreamReader reader = new StreamReader(client); StreamWriter writer = new StreamWriter(client); while (true) { string input = Console.ReadLine(); if (String.IsNullOrEmpty(input)) break; writer.WriteLine(input); writer.Flush(); Console.WriteLine(reader.ReadLine()); } } static void StartServer() { Task.Factory.StartNew(() => { var server = new NamedPipeServerStream("PipesOfPiece"); server.WaitForConnection(); StreamReader reader = new StreamReader(server); StreamWriter writer = new StreamWriter(server); while (true) { var line = reader.ReadLine(); writer.WriteLine("server recieved:" + line); writer.Flush(); } }); } }
桂棹兮兰桨,击空明兮溯流光。