-
大小: 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
- 上一篇:基于WINDOWS10系统发声的文字读取
- 下一篇:C# 秒表 (倒计时)
评论
共有 条评论