简体   繁体   English

WCF命名为管道流

[英]WCF Named Pipe Streaming

I have implemented a server/client test rig that uses streamed transfer mode with a net.pipe binding. 我已经实现了使用流传输模式和net.pipe绑定的服务器/客户端测试装置。 This is all kind of working however I am hitting an issue when the actual server's stream implementation blocks on an empty buffer. 一切都是这样,但是当实际服务器的流实现在空缓冲区中阻塞时,我遇到了一个问题。 Even if i remove all synchronization, set the concurrency mode to multiple I am having an issue where my client application is blocking on stream.Read. 即使我删除了所有同步,也将并发模式设置为多个,但是我的客户端应用程序在stream.Read上阻塞时出现问题。

So my client initiates a connection to the server with a "GetStream" call (on a non-UI thread), the actual stream implementation that's returned by the server is a blocking stream (say NetStream for example) so it will block when there are no bytes available to read. 因此,我的客户端使用“ GetStream”调用(在非UI线程上)启动了到服务器的连接,服务器返回的实际流实现是阻塞流(例如NetStream),因此当存在以下情况时它将阻塞没有可用的字节读取。 This is causing a complete lockup of the service host so now the client cannot make any further calls until the stream.read operation unblocks. 这导致服务主机的完全锁定,因此现在客户端无法再进行任何调用,直到stream.read操作解除阻塞。

Can someone shed some light on this behavior? 有人可以阐明这种行为吗?

I have solved a working code for anonymous pipes, named pipes asynchronous and synchronous. 我已经解决了匿名管道(异步和同步管道)的工作代码。 From my experience I can tell that, you just cannot have shared memory buffer "empty". 从我的经验来看,您不能拥有共享内存缓冲区“空”。 Even in Asynchronous, I believe, background threads are created to read and write synchronously. 我相信,即使在异步模式下,也会创建后台线程以进行同步读写。

So at the moment just consider this for a fact that, 因此,现在考虑一下这个事实,

the server must first send write to buffer => the client should read it => Client must write back to that buffer => Server must read it. 服务器必须首先向缓冲区发送写操作=>客户端应读取它=>客户端必须写回该缓冲区=>服务器必须读取它。

That cycle has to repeat forever for applications to not freeze. 为了不冻结应用程序,该循环必须永远重复。 I am beginning to think this is what makes shared memory communication different via server/client socket. 我开始认为这就是使共享内存通过服务器/客户端套接字进行通信的不同之处。 In shared memory approach you might not have to worry about synchronization also it dedicates client to a server such that client cannot exist with a server. 在共享内存方法中,您可能不必担心同步,它还将客户端专用于服务器,因此客户端不能与服务器一起存在。

You should look at using the older 'async' style Begin/End Read/Write methods to allow asynchronously communication. 您应该查看使用较旧的“异步”样式的Begin / End Read / Write方法以允许异步通信。 Unfortunately there is no async/await support for named pipes in .net - however, you can wrap them using the TaskFactory.FromAsync methods. 不幸的是,.net中没有对命名管道的异步/等待支持-但是,您可以使用TaskFactory.FromAsync方法包装它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM