TCPClient vs Socket in C#

后端 未结 2 999
栀梦
栀梦 2020-12-05 01:24

I don\'t see much use of TCPClient, yet there is a lot of Socket? What is the major difference between them and when would you use each?

I

相关标签:
2条回答
  • 2020-12-05 02:04

    Also, you can access the socket directly from the TCPClient object, it's under the property Client - so there is no performance difference.

    0 讨论(0)
  • 2020-12-05 02:27

    The use of TcpClient and TcpListener just means a few less lines of code. As you say it's just a wrapper over the Socket class so there is no performance difference between them it's purely a style choice.

    Update: Since this answer was posted the .Net source code has become available. It does indeed show that TcpClient is a very light wrapper over the Socket class which is itself a wrapper on top of the native WinSock2 API*.

    • On Windows. Will be different for .Net Standard/Core etc. on other platforms.
    0 讨论(0)
提交回复
热议问题