TcpClient.GetStream().Read() vs. TcpClient.Client.Receive()

前端 未结 3 1327
情书的邮戳
情书的邮戳 2021-01-18 12:20

.NET allows two very similar ways to \"read\" from the network (assuming TCP connection):

1. TcpClient.GetStream().Read() 
2. TcpClient.Client.Receive()
         


        
3条回答
  •  有刺的猬
    2021-01-18 12:36

    There is, in fact, a pretty clear benefit of using the first option (TcpStream and not Socket). The benefit is that stream API is more flexible when different underlying implementations are needed at for the same program.

    For example, a code which sometimes may use SSL and sometimes may not use it, can switch between SslStream and TcpStream with no changes to the calling code. This is something which is much harder to accomplish using only plain Socket API.

提交回复
热议问题