How to ensure NetworkStream to send data immediately without closing the Stream or TcpClient?

前端 未结 1 685
长发绾君心
长发绾君心 2021-01-14 13:48

I have a very simple code snippet that tries to send data via TcpClient and its associated NetworkStream.

var client = new TcpClien         


        
相关标签:
1条回答
  • 2021-01-14 14:32

    Set TcpClient.NoDelay to true so that Nagle's algorithm isn't used.

    From the MSDN Library documentation:

    When NoDelay is false, a TcpClient does not send a packet over the network until it has collected a significant amount of outgoing data. Because of the amount of overhead in a TCP segment, sending small amounts of data is inefficient. However, situations do exist where you need to send very small amounts of data or expect immediate responses from each packet you send. Your decision should weigh the relative importance of network efficiency versus application requirements.

    0 讨论(0)
提交回复
热议问题