用于向客户端广播事件的 OneWay 和异步调用之间有何权衡? (世界CF)

发布于 2024-08-12 02:44:22 字数 320 浏览 10 评论 0原文

我正在编写一个 WCF(目前计划使用 netTcpBinding)客户端/服务器应用程序,该应用程序必须支持“少数”客户端,包括向客户端发送事件。

我不希望服务器阻塞 当客户端处理事件时。

从逻辑上讲,我看不到将回调方法标记为“OneWay”或使用“being_MethodName(..)”调用它们之间的匹配差异

那么每种技术的优点和缺点是什么?


我从阅读中发现OneWay 消息的错误处理很复杂,您可能会意外地使通道变坏...例如,它们不是即发即忘!

I am writing a WCF (netTcpBinding planned at present) client/server application that has to support a “handful” of clients including sending events to the clients.

I do not wish the server to block
while the clients process the events.

Logically I cannot see match difference between marking the callback methods as “OneWay” or calling them with "being_MethodName(..)"

So what are the pros and cons of each technique?


I am finding from my readings that the error handling of OneWay messages is complex and you can unexpectedly get the channel going bad... E.g the are not fire and forget!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

-小熊_ 2024-08-19 02:44:22

从抽象合约定义的角度来看,如果服务器不需要客户端的任何响应,那么就没有理由将其写入与客户端的“合约”中。

在更务实的层面上,您将因必须发送和接收无关消息而产生带宽成本和处理开销。

我关心的另一个主要问题是客户端是否在服务器向客户端发送通知的同一个 TCP 通道上向服务器发送消息。如果是这种情况,您肯定希望使用 OneWay 消息以避免可能的死锁(请参阅我在此线程中的评论:使用回调时 WCF 双工通道关闭)。

另外,需要明确的是,单向和异步并不排斥——您可以而且可能应该使用异步模式发送单向消息。单向消息发送可能会阻塞,例如,如果网络缓冲区已满,因此使用异步将确保您的服务器事件通知线程保持畅通。

From an abstract contract definition POV, if the server does not require any response from the client, then there's no reason to write it into the "contract" with the client.

At a more pragmatic level, you'll be incurring bandwidth costs and processing overhead of having to send and receive the extraneous message.

One other major concern I would have is whether the client is sending messages to the server on the same TCP channel that the server is sending notifications to the client. If that is the case, you definitely want to use OneWay messages so as to avoid a possible deadlock (see my comment in this thread: WCF duplex channel gets closed when using callbacks).

Also, to be clear, one-way and async are not exclusive -- you can and likely should send your one-way messages using the async pattern. It is possible for a one-way message send to block, for example if the network buffer is full, so using async will ensure that your server event notification thread stays unblocked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文