服务端

 private NamedPipeServerStream pipeServer;
private Thread receiveDataThread = null;
public fServer()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
receiveDataThread = new Thread(ReceiveDataFromClient) {IsBackground = true};
receiveDataThread.Start();
}
private void ReceiveDataFromClient()
{
while (true)
{
pipeServer = new NamedPipeServerStream("Server", PipeDirection.InOut, );
pipeServer.WaitForConnection();
StreamReader sr = new StreamReader(pipeServer);
string jsonData = sr.ReadLine();
this.Invoke(new EventHandler(delegate
{
this.tblRecMsg.Text = jsonData+DateTime.Now;
}));
sr.Close();
}
}

客户端

   private void button1_Click(object sender, EventArgs e)
{
try
{
var str = txtSendMsg.Text;
using (NamedPipeClientStream pipeClient =new NamedPipeClientStream(".", "Server", PipeDirection.InOut, PipeOptions.None, TokenImpersonationLevel.None))
{
pipeClient.Connect();
//发送
using (StreamWriter sw = new StreamWriter(pipeClient))
{
sw.WriteLine(str);
sw.Flush();
}
}
}
catch (Exception ex)
{
throw ex;
}
}

c#NamedPipe命名管道通信例子的更多相关文章

  1. C#命名管道通信

    C#命名管道通信 最近项目中要用c#进程间通信,以前常见的方法包括RMI.发消息等.但在Windows下面发消息需要有窗口,我们的程序是一个后台运行程序,发消息不试用.RMI又用的太多了,准备用管道通 ...

  2. Linux学习记录--命名管道通信

    命名管道通信 什么是命名管道 一个主要的限制是,它是匿名管道的应用还没有名字,因此,只有它可以用于进程间通信的方式与亲缘关系.在命名管道(named pipe或FIFO)提出后,该限制得到了克服.FI ...

  3. C++和C#进程之间通过命名管道通信(上)

    C++和C#进程之间通过命名管道通信(上) "命名管道"是一种简单的进程间通信(IPC)机制.命名管道可在同一台计算机的不同进程之间,或在跨越一个网络的不同计算机的不同进程之间,支 ...

  4. c# c++通信--命名管道通信

    进程间通信有很多种,windows上面比较简单的有管道通信(匿名管道及命名管道) 最近做个本机c#界面与c++服务进行通信的一个需求.简单用命名管道通信.msdn都直接有demo,详见下方参考. c+ ...

  5. linux命名管道通信过程

    前一个道,这节学习命名管道. 二命名管道 无名管道仅仅能用来在父子进程或兄弟进程之间进行通信,这就给没有亲缘关系的进程之间数据的交换带来了麻烦.解决问题就是本节要学习的还有一种管道通信:命名管道. 命 ...

  6. windows10使用VS(VC++)创建c++多进程命名管道通信

    代码可以在 这里 下载 代码主要涉及到: 管道通信 多线程(含临界区) 多进程通信 创建的子进程独立运行 更新日志: 04-12-2020 1. 去除自定义函数返回值,改为int作为函数返回值并增加相 ...

  7. windows namedPipe 命名管道clent and server

    1.client: #include "iostream" #include "windows.h" using namespace std; void mai ...

  8. C#使用(NamedPipe)命名管道通信的例子

    https://blog.csdn.net/yl2isoft/article/details/20228279

  9. 命名管道-MSDN例子

    服务器: #include "stdafx.h" #include <windows.h> #include <stdio.h> #include < ...

随机推荐

  1. mysql基础---->mybatis的批量插入(一)

    这里面记录一下使用mybatis处理mysql的批量插入的问题,测试有可能不准.只愿世间风景千般万般熙攘过后,字里行间,人我两忘,相对无言. mybatis的批量插入 我们的测试主体类是springb ...

  2. Apache Maven 打包可执行jar

    在本文的 参考资料 部分,您将发现大量介绍 Maven 的入门教程.本文的 5 个技巧目的是帮助您解决即将出现的一些问题:使用 Maven 管理您的应用程序的生命周期时,将会出现的编程场景. 1. 可 ...

  3. J - Intersection

    来源poj 1410 You are to write a program that has to decide whether a given line segment intersects a g ...

  4. linux 下实用软件工具推荐

    截图:Deepin-Screenshot 音乐:deepin-music netease-music 绘图工具:Draw.io Desktop (chrome extension) / www.pro ...

  5. np.mgird np.ogrid

    np.ogrid: address:https://docs.scipy.org/doc/numpy/reference/generated/numpy.ogrid.html returns an o ...

  6. Jexus .Net at System.Net.Sockets.Socket.Connect (System.Net.IPAddress[] addresses, System.Int32 port)

    环境:Jexus(独立版)+MVC(5.2.3) +Redis+EF(6.0) Application Exception System.Net.Sockets.SocketException Con ...

  7. php后台对接ios,安卓,API接口设计和实践完全攻略,涨薪必备技能

    2016年12月29日13:45:27    关于接口设计要说的东西很多,可能写一个系列都可以,vsd图都得画很多张,但是由于个人时间和精力有限,所有有些东西后面再补充   说道接口设计第一反应就是r ...

  8. FileZilla:425 Can't open data connection for transfer of解决办法

    状况描述: 服务器端采用的Windows 2008系统,安装了FileZilla Server,客户端采用的FileZilla Client,客户端在连接服务器端的时候,可以正常通过验证,但是在列出目 ...

  9. [No0000D5]便利所有子目录更改后缀名bat

    pause for /r %%i in (.) do ( cd %%i ren *.txt *.dll ) pause

  10. pytorch定义一个简单的神经网络

    刚学习pytorch,简单记录一下 """ test Funcition """ import torch from torch.autog ...