两台服务器监听同一个地址
我有一个可能运行多个实例的应用程序。我有一个同时在所有实例上执行的任务。 我想安排一个操作系统任务来运行一个通过命名管道发送消息的小应用程序,并且我想让我的所有实例都侦听该管道并执行其操作。 我尝试了 WCF 命名管道,并在尝试运行第二个实例时收到了 AddressAlreadyInUseException。
可行吗?有道理吗?我的目标是找到正确的解决方案吗? (并不是说我不需要从应用程序向调用者发送回复)
I have an appliction that might be running multiple instances. I have a task that executes on all instances at the same time.
I want to schedule an OS task to run a small app that sends message trough a named pipe, and I want to have all my instnces listenning on that pipe and doing their stuff.
I tried WCF named pipes and got AddressAlreadyInUseException when I tried to run the second instnce.
Is it doable? Does it make sense? Am I aiming for the right solution? (Not that I don't need to send a reply from the appliction to the caller)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
典型的方法是这样的:
“工人”不需要监听管道或套接字;您必须对它们进行不同的配置,并将此配置传达给“负载均衡器”。通过侦听“负载均衡器”,每个“工作人员”都可以进行相同的配置,并且只需要知道如何联系“负载均衡器”。
A typical approach is like this:
'Workers' need not listen on a pipe or a socket; you'd have to configure each of them differently and communicate this config to the 'load balancer'. With a listening 'load balancer', each 'worker' can be configured identically and only needs to know how to contact the 'load balancer'.
Windows 管道(就像输送油、水或其他物质的真实管道)只有两端,一端是服务器,另一端是单个客户端。
您不能让多个客户端在单个管道上“侦听”,并且沿着管道发送的每条消息都将由单个接收器接收。
您可以让多个服务器全部侦听同一管道名称上的管道连接,但管道名称只是一个集合点,而不是共享管道实例。连接到命名管道的每个客户端都将通过单个管道实例连接到单个服务器(客户端无法选择)。没有可靠的方法来枚举所有侦听服务器。 (如果您想使用 WCF,命名管道绑定创建和发布实际的管道名称 意味着,正如您所发现的,一次只有一个服务进程可以侦听特定的服务 url)。
两种可能的方法:
我建议第二种方法不太脆弱(邮槽通信完全是一种方法,因此有更大的范围来难以诊断错误)。
Windows Pipes (like real pipes which carry oil, water, or whatever) have just two ends, one end the server, the other a single client.
You can't have multiple clients "listening" on a single pipe, and each message sent down a pipe will be received by a single receiver.
You can have multiple servers all listening for pipe connections on the same pipe name, but the pipe name is just a rendezvous point, not a shared pipe instance. Each client connecting to the named pipe will be connected to a single server (which the client can't choose) by a single pipe instance. There is no reliable way to enumerate all listening servers. (And if you want to use WCF, the way the named pipe binding creates and publishes the actual pipe name means that, as you have discovered, only one service process at a time can listen on a particular service url).
Two possible approaches:
I would recommend the second approach as being less brittle (mailslot communication is entirely one way, so there is more scope for difficult to diagnose errors).