zoukankan      html  css  js  c++  java
  • Named pipe Stream include NamedPipeServerStream and NamedPipeClientStream

    Named pipe (more flexible)
    Allows two-way communication between arbitrary processes on the same computer or different computers across a network.A pipe is good for interprocess communication (IPC) on a single computer: it doesn’t rely on a network transport, which means no network protocol overhead, and it has no issues with firewalls.

    Server:

    static NamedPipeServerStream serverStream;
            static int i = 0;
            static void NamedPipeServerStreamDemo()
            {
                serverStream = new NamedPipeServerStream("FredPipeServerStream");
                serverStream.WaitForConnection();           
                System.Timers.Timer timer = new System.Timers.Timer(100);
                timer.Elapsed += Timer_Elapsed;
                timer.Start();                 
            }
    
            private static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
            {
                string str = $"i is {i},now is {DateTime.Now.ToString("yyyyMMddHHmmssffff")},Guid is {Guid.NewGuid()}";
                byte[] serverBytes = Encoding.UTF8.GetBytes(str);
                serverStream.Write(serverBytes, 0, serverBytes.Length);
                i++;
            }

    Client:

    static void NamedPipeClientStreamDemo()
            {
                var clientStream = new NamedPipeClientStream("FredPipeServerStream");
                clientStream.Connect();
                while(true)
                {
                    byte[] receiveData = new byte[100];
                    int result = clientStream.Read(receiveData, 0, receiveData.Length);
                    string str = Encoding.UTF8.GetString(receiveData);
                    Console.WriteLine($"Client receive {str}");
                }           
            }
  • 相关阅读:
    夜神模拟器连接电脑
    Appium+python 多设备自动化测试
    appium+python 连接手机设备的yaml配置文件
    appium+python自动化测试连接设备
    Ansible 学习目录
    Python 时间处理
    获取本机网卡ip地址
    Ansible playbook 使用
    ansible hosts配置
    python os和sys模块使用
  • 原文地址:https://www.cnblogs.com/Fred1987/p/13030066.html
Copyright © 2011-2022 走看看