C# Why doesn't “Flush” force the bytes down the network stream?

前端 未结 4 767
我在风中等你
我在风中等你 2021-01-12 00:04

I have a project where I\'m trying to send a serialized object to the server, then wait for an "OK" or "ERROR" message to come back.

I seem to be

4条回答
  •  一个人的身影
    2021-01-12 00:38

    Uh oh, you can blame Nagle's algorithm. It has nothing to do with C# though, it is a default behavior for TCP/IP stack. Enable NoDelay socket option using SetSocketOption method. But be careful, disabling Nagle's algorithm will downgrade the throughput.

    I'm also not sure about that stream you are using on top of the socket, as I am not a C# developer at all, but try to drop its instance so it does write for sure :-)

提交回复
热议问题