示例#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();

                    var ss = new StreamString(pipeClient);
                    // Validate the server's signature string.
                    if (ss.ReadString() == "I am the one true server!")
                    {
                        // The client security token is sent with the first write.
                        // Send the name of the file whose contents are returned
                        // by the server.
                        ss.WriteString("textfile.txt");

                        // Print the file to the screen.
                        Console.Write(ss.ReadString());
                    }
                    else
                    {
                        Console.WriteLine("Server could not be verified.");
                    }
                    pipeClient.Close();
                    // Give the client process some time to display results before exiting.
                    Thread.Sleep(4000);
                }
            }
            else
            {
                Console.WriteLine("\n*** Named pipe client stream with impersonation example ***\n");
                StartClients();
            }
        }
示例#2
0
        void Connection()
        {
            NamedPipeClientStream pipeClient =
                    new NamedPipeClientStream(".", "testpipe",
                        PipeDirection.InOut, PipeOptions.None,
                        TokenImpersonationLevel.Impersonation);

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

                StreamString ss = new StreamString(pipeClient);
                // Validate the server's signature string
                if (ss.ReadString() == "I am the one true server!")
                {
                    txtClient.Text += "\r\n" + "connected";
                    connectionVerified = true;
                    // The client security token is sent with the first write.
                    // Send the name of the file whose contents are returned
                    // by the server.
                    ss.WriteString("c:\\textfile.txt");

                    // Print the file to the screen.
                    Console.Write(ss.ReadString());
                }
                else if (connectionVerified == true)
                {
                    if (ss.ReadString() == "test")
                    {

                        returnMessage = "message to send back";
                        ss.WriteString(returnMessage);
                        txtClient.Text += "\r\n" + returnMessage + "sent";
                    }
                }
                else
                {
                    txtClient.Text += "\r\n" + "server not verified";
                }
        }