Socket “Flush” by temporarily enabling NoDelay

前端 未结 4 1239
萌比男神i
萌比男神i 2020-12-17 02:14

Background

I have an implementation of an HTTP server in C#. Using ab I discovered a weird performance issue. Each request took 5 ms with Keep-Alive Off but 40 ms w

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-17 02:40

    If you know the the length of the data you are sending,Setting SendBufferSize will make the socket send the data at once, Following is a working code example:

    byte[] bytesToSend = ASCIIEncoding.ASCII.GetBytes(message);
    socket.SendBufferSize = bytesToSend.Length;
    socket.Send(bytesToSend);
    

提交回复
热议问题