Non blocking socket writing in Java is compared with blocking socket writing

Why does someone prefer to block writes and non blocking writes? My understanding is that if you want to ensure that the other party gets the TCP packet after the write method returns, you just want to block the write, but I'm not even sure if it's possible You must flush and flush the socket buffer written by the underlying operating system So what are the disadvantages of non blocking socket writing? Is having a large underlying write socket buffer a bad idea in terms of performance? My understanding is that the smaller the underlying socket write buffer, the more likely you are to encounter slow / wrong clients, and you must discard / queue packets at the application level when the underlying socket buffer is full and iswritable() returns false

Solution

Your understanding is incorrect It cannot ensure this

Blocking writes blocking until all data has been transferred to the socket send buffer, from where it is transferred asynchronously to the network If the reader is slow, its socket receive buffer will fill up, which will eventually cause the socket send buffer to fill up, which will cause blocking, write blocking and blocking the whole thread Nonblocking I / O provides you with a way to detect and handle this situation

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>