• 大小: 0.17M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-02-23
  • 语言: C#
  • 标签: NamedPipes  

资源简介

命名管道

This is a proof of concept / pattern concept for creating a client/server communication model with named pipes in C#. In this example, a client passes a message to the server over a named pipe which is then executed as a command on the server. The standard out and standard error are redirected back to the client over the named pipe and printed to the terminal screen.

资源截图

代码片段和文件信息

using System;
using System.IO;
using System.IO.Pipes;
using System.Text;

namespace Client
{
    class Client
    {
        static void Main(string[] args)
        {
            using (var pipe = new NamedPipeClientStream(“localhost“ “psexecsvc“ PipeDirection.InOut))
            {
                pipe.Connect(5000);
                pipe.ReadMode = PipeTransmissionMode.Message;
                do
                {
                    Console.Write(“csexec> “);
                    var input = Console.ReadLine();
                    if (String.IsNullOrEmpty(input)) continue;
                    byte[] bytes = Encoding.Default.GetBytes(input);
                    pipe.Write(bytes 0 bytes.Length);
                    if (input.ToLower() == “exit“) return;
                    var result = ReadMessage(pipe);
                    Console.WriteLine(Encoding.UTF8.GetString(result));
                    Console.WriteLine();
                } while (true);
           

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-08-08 16:28  NamedPipes-master\
     目录           0  2018-08-08 16:28  NamedPipes-master\Client\
     文件        2265  2018-08-08 16:28  NamedPipes-master\Client\Client.csproj
     文件        1509  2018-08-08 16:28  NamedPipes-master\Client\Program.cs
     目录           0  2018-08-08 16:28  NamedPipes-master\Client\Properties\
     文件        1419  2018-08-08 16:28  NamedPipes-master\Client\Properties\AssemblyInfo.cs
     文件         134  2018-08-08 16:28  NamedPipes-master\Client\app.config
     文件        1589  2018-08-08 16:28  NamedPipes-master\NamedPipes.sln
     文件         470  2018-08-08 16:28  NamedPipes-master\README.md
     目录           0  2018-08-08 16:28  NamedPipes-master\Server\
     文件        2770  2018-08-08 16:28  NamedPipes-master\Server\Program.cs
     目录           0  2018-08-08 16:28  NamedPipes-master\Server\Properties\
     文件        1419  2018-08-08 16:28  NamedPipes-master\Server\Properties\AssemblyInfo.cs
     文件        2091  2018-08-08 16:28  NamedPipes-master\Server\Server.csproj
     文件      207262  2018-08-08 16:28  NamedPipes-master\screen.png

评论

共有 条评论

相关资源