zoukankan      html  css  js  c++  java
  • NamedPipeStream的使用

    NamedPipeStream的使用具体案例如下:

    using System;
    using System.Data;
    using System.Data.SQLite;
    using System.IO;
    using System.IO.Pipes;
    using System.Net;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    
    namespace SupremeConsole
    {
        class Program
        {
            static void Main(string[] args)
            {
                #region 测试  NamedPipeStream
                new Thread(new ThreadStart(PipeServer)).Start();
                new Thread(new ThreadStart(PipeClient)).Start();
                #endregion
             } 
        public static void PipeServer()
            {
                var s = new NamedPipeServerStream("pipedream");
                s.WaitForConnection();
                while (true)
                {
                   
                    s.WriteByte(100);
                    Console.WriteLine($"PipeServer 收到 客户端 数据:{s.ReadByte()}");
                }
            }
    
            public static void PipeClient()
            {
    
               var s = new NamedPipeClientStream("pipedream");
                s.Connect();
                while (true)
                {
                    
                    Console.WriteLine($"PipeClient 收到服务端数据:{s.ReadByte()}");
                    Thread.Sleep(TimeSpan.FromSeconds(2));
                    s.WriteByte(200); // Send the value 200 back.
                }
            }
         }
    }

     测试结果:

  • 相关阅读:
    数据库练习
    pymysql
    数据库索引
    数据库查询
    数据库操作
    数据库建表
    数据库初识
    shell 编程
    Struts2与SpringMVC
    SpringAOP
  • 原文地址:https://www.cnblogs.com/1175429393wljblog/p/11910407.html
Copyright © 2011-2022 走看看