原始 Socket 和 UdpClient 之间的性能(或其他)差异? [英] The performance (or other) differences between raw Socket and UdpClient?

查看:118
本文介绍了原始 Socket 和 UdpClient 之间的性能(或其他)差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我们所知,.Net 有 UdpClient 用于 UDP 的简单套接字使用.

As we know .Net has UdpClient for simple Socket usage for UDP.

来自 MSDN:

如果您正在编写一个相对简单的应用程序并且不需要最高性能,请考虑使用 TcpClient、TcpListener 和 UdpClient.这些类为 Socket 通信提供了一个更简单、更用户友好的界面.

If you are writing a relatively simple application and do not require maximum performance, consider using TcpClient, TcpListener, and UdpClient. These classes provide a simpler and more user-friendly interface to Socket communications.

我想知道 Raw Socket 和 UdpClient 之间的性能差异有多大?我知道 UdpClient 是 Udp 套接字的包装器,它没有异步读/写.

I am wondering how much performance differences between Raw Socket and UdpClient? I know UdpClient is a wrapper of socket for Udp and it does not have asynchron read/write.

还有什么吗?

谢谢

推荐答案

正如文档所说,UdpClient/TcpClient 是 Socket 类之上的一个瘦包装器.如果您只想发送/接收数据块,那么这些类很好.对于这个场景,Socket 和 UdpClient/TcpClient 的性能没有区别.

As the docs say, UdpClient/TcpClient are a thin wrapper on top of Socket class. If all you want to do is send/receive blobs of data, then these classes are good. For this scenario, there is no difference in performance between Socket and UdpClient/TcpClient.

然而,Socket 确实以 XXXAsync() 方法的形式提供了一种更快的方式来进行 IO.这些方法允许您执行非常快的 I/O,并且不会在 TcpClient/UdpClient 中公开.这就是文档所说的性能差异"的含义——为了获得更快的性能,您必须深入研究 Socket 类并使用这些方法 (XXXAsync).

However, Socket does provide a faster way to do IO, in the form of XXXAsync() methods. These methods allow you to do very fast I/O, and are not exposed in TcpClient/UdpClient. That is what the docs mean by "perf difference" - it is that for faster perf, you will have to dig into Socket class and use these methods (XXXAsync).

这篇关于原始 Socket 和 UdpClient 之间的性能(或其他)差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆