.net 的多线程网络 UDP 服务器库
.net 领域是否有类似twisted (python) 或eventmachine (ruby) 的东西?
我还需要这个抽象吗?我正在监听一个 IO 设备,该设备将向我发送连接到它的三个或四个模拟传感器的事件。简单地使用循环 UdpClient
有哪些风险?我不能错过任何事件,但是 ip 堆栈会为我处理消息排队吗?所有这些是否都取决于我收到消息后线程尝试执行的工作量?
我在抽象中寻找的是消除问题中线程和同步的复杂性。
Is there something like twisted (python) or eventmachine (ruby) in .net land?
Do I even need this abstraction? I am listening to a single IO device that will be sending me events for three or four analog sensors attached to it. What are the risks of simply using a looped UdpClient
? I can't miss any events, but will the ip stack handle the queuing of messages for me? Does all of this depend on how much work the thread tries to do once I receive a message?
What I'm looking for in an abstraction is to remove the complication of threading and synchronization from the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为你把事情搞得太复杂了。
只需打开 1 个 UDP 套接字,并在其上设置异步回调即可。对于每个传入的数据包,将其放入队列中,并再次设置回调。就是这样。
确保在排队和出队时对队列设置锁。
就这么简单,而且性能会很棒。
右
I think you are making it too complicated.
Just have 1 UDP socket open, and set an async callback on it. For every incoming packet put it in a queue, and set the callback again. Thats it.
make sure that when queuing and dequeueing you set a lock on the queue.
it's as simple as that and performance will be great.
R
我会推荐 ICE 它是一个通信引擎,可以为您抽象线程和通信(文档有点详尽)。
I would recommend ICE it's a communication engine that will abstract threading and communication to you (documentation is kind of exhaustive).
问题是,使用 Udp,您会自动承担丢失数据包的风险。我已经阅读了 ICE 的文档(正如 Steve 建议的那样),它非常详尽。 ICE 似乎适用于 Udp,但开发人员似乎更喜欢 Tcp。我从 ICE 文档中了解到,它没有提供任何强化机制来确保可靠的 Udp 通信。
实际上,设置异步 Udp 客户端或服务器非常容易。您真正的工作是检查完整的数据包和缓冲。异步实现应该让您无需管理线程。
Problem is that with Udp you are automatically assuming the risk of lost packets. I've read the documentation on ICE (as Steve suggested), and it is very exhaustive. It appears that ICE will work for Udp, however, it appears that Tcp is preferred by the developers. I gather from the ICE documentation that it does not provide any intensive mechanisms to ensure reliable Udp communications.
It is actually very easy to set up an asynchronous Udp client or server. Your real work comes in checking for complete packets and buffering. The asynchronous implementations should keep you from managing threads.
听起来您正在寻找可靠的多播 - 您可以尝试 RMF ,它将提供可靠性和使用异步回调从传入消息队列传递消息。 IBM 还开发了具有 UDP 组件的 WebSphere。 EmCaster 也是一种选择 - 然而开发似乎在 2008 年就停止了。
如果您不打算将这些数据包(或事件)传输到其他计算机,您可能只想使用一些简单的东西,例如内存映射文件或其他形式的工控机。
It sounds like you are looking for reliable multicast -You could try RMF , it will do the reliability and deliver the messages using asyc callbacks from the incoming message queue. IBM also does WebSphere which has a UDP component. EmCaster is also an option - however development seems to have stopped back in 2008.
If you aren't going to be transmitting these packets (or events) to other machines you might just want to use something simple like memory mapped files or other forms of IPC.