Example #1
0
        public static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                if (args[0] == "spawnclient")
                {
                    var pipeClient = new NamedPipeClientStream(".", "testpipe", PipeDirection.InOut,
                                                               PipeOptions.None, TokenImpersonationLevel.Impersonation);

                    Console.WriteLine("Connecting to server...\n");
                    pipeClient.Connect();

                    StreamString ss = new StreamString(pipeClient);
                    if (ss.ReadString() == "I am the one true server!")
                    {
                        ss.WriteString(Environment.CurrentDirectory + "\\testdata.txt");
                        Console.Write(ss.ReadString());
                    }
                    else
                    {
                        Console.WriteLine("Server could not be verified.");
                    }

                    pipeClient.Close();
                    Thread.Sleep(4000);                     // Give the client process some time to display results before exiting.
                }
            }
            else
            {
                Console.WriteLine("\n*** Named pipe client stream with impersonation example ***\n");
                StartClients();
            }
        }
Example #2
0
        public static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                if (args[0] == "spawnclient")
                {
                    var pipeClient = new NamedPipeClientStream(".", "testpipe", PipeDirection.InOut,
                        PipeOptions.None, TokenImpersonationLevel.Impersonation);

                    Console.WriteLine("Connecting to server...\n");
                    pipeClient.Connect();

                    StreamString ss = new StreamString(pipeClient);
                    if (ss.ReadString() == "I am the one true server!")
                    {
                        ss.WriteString(Environment.CurrentDirectory + "\\testdata.txt");
                        Console.Write(ss.ReadString());
                    }
                    else
                    {
                        Console.WriteLine("Server could not be verified.");
                    }

                    pipeClient.Close();
                    Thread.Sleep(4000); // Give the client process some time to display results before exiting.
                }
            }
            else
            {
                Console.WriteLine("\n*** Named pipe client stream with impersonation example ***\n");
                StartClients();
            }
        }
Example #3
0
        private static void ServerThread(object data)
        {
            var pipeServer = new NamedPipeServerStream("testpipe", PipeDirection.InOut, numThreads);
            int threadId   = Thread.CurrentThread.ManagedThreadId;

            pipeServer.WaitForConnection();

            Console.WriteLine("Client connected on thread[{0}].", threadId);
            try
            {
                StreamString ss = new StreamString(pipeServer);
                ss.WriteString("I am the one true server!");
                string           filename   = ss.ReadString();
                ReadFileToStream fileReader = new ReadFileToStream(ss, filename);
                Console.WriteLine("Reading file: {0} on thread[{1}] as user: {2}.",
                                  filename, threadId, pipeServer.GetImpersonationUserName());
                pipeServer.RunAsClient(fileReader.Start);
            }
            catch (IOException e)
            {
                Console.WriteLine("ERROR: {0}", e.Message);
            }
            pipeServer.Close();
        }
Example #4
0
        private static void ServerThread(object data)
        {
            var pipeServer = new NamedPipeServerStream("testpipe", PipeDirection.InOut, numThreads);
            int threadId = Thread.CurrentThread.ManagedThreadId;

            pipeServer.WaitForConnection();

            Console.WriteLine("Client connected on thread[{0}].", threadId);
            try
            {
                StreamString ss = new StreamString(pipeServer);
                ss.WriteString("I am the one true server!");
                string filename = ss.ReadString();
                ReadFileToStream fileReader = new ReadFileToStream(ss, filename);
                Console.WriteLine("Reading file: {0} on thread[{1}] as user: {2}.",
                    filename, threadId, pipeServer.GetImpersonationUserName());
                pipeServer.RunAsClient(fileReader.Start);
            }
            catch (IOException e)
            {
                Console.WriteLine("ERROR: {0}", e.Message);
            }
            pipeServer.Close();
        }
Example #5
0
 public ReadFileToStream(StreamString str, string filename)
 {
     fn = filename;
     ss = str;
 }
Example #6
0
 public ReadFileToStream(StreamString str, string filename)
 {
     fn = filename;
     ss = str;
 }