NamedPipe多台服务器 [英] NamedPipe multiple servers

查看:443
本文介绍了NamedPipe多台服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于简单的IPC我选择了NamedPipes过程(本地)之间的通信。



由于不断变化的需求应当有服务器的多个实例,从而导致多个听众在同一pipename。



但是,似乎是一个问题。只有那些听众一得到消息,所有其他实例不会。是否有广播消息的某种方式?



我已经看到的这个问题,这基本上是同样的问题,但一直无人接听。



代码:



现在我用的是pipeserver非常相似的这个答案



我的客户(在这种情况下,发送方)的代码是:

 公共静态无效SendToPipe(字符串pipeName,字符串数据)使用
{
(VAR p =新NamedPipeClientStream(pipeName ))
{
p.Connect();

使用(无功W =新的StreamWriter(P))
{
w.WriteLine(数据);
w.Flush();
}
}
}

respectivly:

静态无效的主要(字串[] args)
{
SendToPipe(DEFAULT_PIPE_NAME,一些字符串传递);
}


解决方案

最后,我已经找到了解决方案(不肯定这是最优的 - 但它的工作)。它是基于使用的 NamedPipeClientStream.NumberOfServerInstances
看看我的 问题线程


For simple IPC I have chosen NamedPipes to communicate between process (local).

Due to changing requirements there shall be multiple instances of the server, which leads to multiple "listeners" on the same pipename.

But there seems to be a problem. Only one of those listeners gets the message, every other instance does not. Is there some way of "broadcasting" messages?

I already have seen this question, which is basically the same question, but it has no answer.

CODE:

Right now I use the pipeserver very similar to this answer

My client (in this case sender) code is:

public static void SendToPipe(string pipeName, string data)
{
    using (var p = new NamedPipeClientStream(pipeName))
    {
        p.Connect();

        using (var w = new StreamWriter(p))
        {
            w.WriteLine(data);
            w.Flush();
        }
    }
}

respectivly:

static void Main(string[] args)
{
    SendToPipe("DEFAULT_PIPE_NAME", "Some string to transmit");
}

解决方案

Finally I've found a solution (don't sure it's optimal - but it's working). It is based on using NamedPipeClientStream.NumberOfServerInstances. Look at my question thread

这篇关于NamedPipe多台服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆