I am creating a named pipe server with my .NET application and its name is "TSPipe". Then I open Notepad and try to save the file to "\. \ Pipe \ TSPipe". Then I want to be able to read what notepad wrote for this channel.
I am still developing common logic for a stream that processes NamedPipeServerStream, but here is my code for the pipe named server:
public void PipeThread() {
var sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
var rule = new PipeAccessRule(sid, PipeAccessRights.ReadWrite, AccessControlType.Allow);
var sec = new PipeSecurity();
sec.AddAccessRule(rule);
while (continuePipeThread) {
pipeStream = new NamedPipeServerStream("TSPipe", PipeDirection.In, 100, PipeTransmissionMode.Byte, PipeOptions.None, 0, 0, sec);
Program.Output.PrintLine("Waiting for connection...");
pipeStream.WaitForConnection();
Program.Output.PrintLine("Connected, reading...");
byte[] data = new byte[1024];
int lenRead = 0;
lenRead = pipeStream.Read(data, 0, data.Length);
string line = System.Text.Encoding.ASCII.GetString(data, 0, lenRead);
Program.Output.PrintLine(line);
pipeStream.Close();
pipeStream.Dispose();
}
}
Thanks in advance for any help, but I'll let you know if any of the suggestions helps!
source
share