private static void ServerThread(object data) { NamedPipeServerStream pipeServer = new NamedPipeServerStream("testpipe", PipeDirection.InOut, numThreads); int threadId = Thread.CurrentThread.ManagedThreadId; // Wait for incoming connections. pipeServer.WaitForConnection(); // Connection attempted. Console.WriteLine($"Client pipe connecting on thread {threadId}."); try { // Create StreamString object. StreamString ss = new StreamString(pipeServer); ss.WriteString("Delphi"); string filename = ss.ReadString(); // Read file. ReadFileToStream fileReader = new ReadFileToStream(ss, filename); Console.WriteLine("Reading file: {0} on thread[{1}] as user: {2}.", filename, threadId, pipeServer.GetImpersonationUserName()); // Run the NamedPipeServerStream as a client (connection success). pipeServer.RunAsClient(fileReader.Start); } catch (IOException e) { Console.WriteLine("ERROR: {0}", e.Message); } pipeServer.Close(); }
public void Start() { string contents = File.ReadAllText(fn); ss.WriteString(contents); }