使用这个答案中的代码- Async two-way communication with Windows Named Pipes (.Net) -我发现任何时候的最大连接/客户端数量都是10。
在下面的粗略示例中(使用多个线程-如果使用多个进程,也会发生同样的事情),客户端1到10将正常启动和运行。但是,当调用'ProcessData‘时,客户端11和12将阻塞,最终抛出TimeoutException。
public static void Start()
{
// Start Server
new Thread(new ThreadStart(Server.MainRun)).Start();
// Start Clients
for (int i = 1; i <= 12; i++)
{
Thread.Sleep(500);
Client c = new Client(i.ToString());
new Thread(new ThreadStart(c.Run)).Start();
}
}
// Create a contract that can be used as a callback
public interface IMyCallbackService
{
[OperationContract(IsOneWay = true)]
void NotifyClient();
}
// Define your service contract and specify the callback contract
[ServiceContract(CallbackContract = typeof(IMyCallbackService))]
public interface ISimpleService
{
[OperationContract]
string ProcessData();
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class SimpleService : ISimpleService
{
public string ProcessData()
{
// Get a handle to the call back channel
var callback = OperationContext.Current.GetCallbackChannel<IMyCallbackService>();
callback.NotifyClient();
return DateTime.Now.ToString();
}
}
class Server
{
public static void MainRun()
{
// Create a service host with an named pipe endpoint
using (var host = new ServiceHost(typeof(SimpleService), new Uri("net.pipe://localhost")))
{
host.AddServiceEndpoint(typeof(ISimpleService), new NetNamedPipeBinding(), "SimpleService");
host.Open();
Console.WriteLine("Simple Service Running...");
Console.ReadLine();
host.Close();
}
}
}
class Client : IMyCallbackService
{
string _id;
public Client(string ID)
{
_id = ID;
}
public void Run()
{
Console.WriteLine("Starting client : " + _id);
// Consume the service
var factory = new DuplexChannelFactory<ISimpleService>(new InstanceContext(this), new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/SimpleService"));
var proxy = factory.CreateChannel();
Console.WriteLine(proxy.ProcessData());
Console.WriteLine("Client finished : " + _id);
}
public void NotifyClient()
{
Console.WriteLine("Notification from Server");
}
}如果客户端在完成后关闭通道(factory.Close()),那么所有客户端都将能够运行。
我理解这个问题- Number of Clients that can connect to a Named Pipe -非常相似,但建议没有下限。
这表明,在Windows和2000机器上- http://msdn.microsoft.com/en-us/library/system.io.pipes.namedpipeclientstream.aspx -的限制是10,除非这发生在Windows8机器和Windows2008服务器上。
有没有办法改变这个限制?我是不是漏掉了什么明显的东西?
发布于 2015-01-30 10:55:34
在这个问题被问到一年后,谷歌把我带到了这里。我想我也可以发帖来帮助其他最终来到这里的人。我想我知道为什么10个人的限制。
您知道NetNamedPipeBinding.MaxConnections属性吗?
获取或设置允许到使用命名管道绑定配置的终结点的最大连接数(入站和出站)。..。此绑定允许的命名管道连接的最大数量。默认值为10。
发布于 2017-04-25 16:46:25
"guest“是正确的,来自MSDN的an old blog帖子证实了这一点在当前的.net版本中仍然适用。
它还建议将默认设置定义为用于开发环境和“小型”部署。
从其他设置(例如,缓冲区大小)来看,我建议每个连接的开销应该大于8KB。
我还没有找到任何关于如果值调整为更大的值(例如,>1000)会出现什么问题的信息: API似乎针对较短的突发请求进行了调整,我怀疑对于较大的值,它可能只是效率低下(不太适合内存,而只是内部实现)-
我欢迎任何关于性能/问题(或成功)的证据,大量客户端连接到一个端点。
https://stackoverflow.com/questions/19252047
复制相似问题