using System;
using System.Threading;
class Program
{
static void Main(string[] args)
{
//建立一个线程,用来监听管道数据
Program p = new Program();
Thread nonParameterThread = new Thread(new ThreadStart(p.StartServerNamedPipe));
nonParameterThread.Start();
Console.WriteLine("我是服务端,你可以通过客户端给我发消息了");
}
///
/// 启动命名管道
///
public void StartServerNamedPipe()
{
m_serverNamedPipe = new NamedPipeServer("test_named_pipe");
m_serverNamedPipe.Readed += OnPipeReadMsg;
m_serverNamedPipe.Start();
}
///
/// 收到管道数据
///
///
///
public string OnPipeReadMsg(string arg)
{
Console.WriteLine("客户端发过来的数据:\r\n{0}\r\n", arg);
return string.Format(" 字符串长度:{0} ", arg.Length);
}
private NamedPipeServer m_serverNamedPipe;
}