NamedPipe multiple servers

余生颓废 提交于 2019-12-13 14:08:59

问题


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");
}

回答1:


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



来源:https://stackoverflow.com/questions/25427692/namedpipe-multiple-servers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!