[英]Why TcpListener does not implement IDisposable
To better understand how the .NET networking part works, I'm going through the reference source of the TcpListener( Documentation , Reference Source ) class. 为了更好地理解.NET网络部分的工作原理,我将浏览TcpListener( Documentation , Reference Source )类的参考源 。 What caught my attention is that it owns the object implementing IDisposable (Socket) but does not implement IDisposable itself.
引起我注意的是它拥有实现IDisposable(Socket)的对象,但没有实现IDisposable本身。 Is there a reason for this?
是否有一个原因?
Because when you use the IPEndPoint
based constructor , the TcpListener
doesn't own the socket. 因为当您使用基于
IPEndPoint
的构造函数时 , TcpListener
不拥有该套接字。 It would be very rude to dispose of said socket if you planned on reusing said IPEndPoint
object 如果您计划重新使用所述
IPEndPoint
对象,那么处理所述套接字将是非常粗鲁的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.