In Java IO, it OutputStreamcan use a method flush()to ensure that data is sent immediately.
OutputStream
flush()
Is there a corresponding feature in Java NIO for SocketChannel? As far as I know, there is a method force()for FileChanneldata reset.
SocketChannel
force()
FileChannel
Maybe a very naive question ...
Use .force()or.getFD.sync()
.force()
.getFD.sync()
Update. Since you clarified your question to be more specific in the SocketChannel (it was generally NIO), please see my answer.
OutputStream.flush() , BufferedOutputStream ObjectOutputStream PrintStream, .
OutputStream.flush()
BufferedOutputStream
ObjectOutputStream
PrintStream
, , FileChannel.force() getFD().sync(). JVM ( ) .
FileChannel.force()
getFD().sync()
SocketChannel.write() โโ: . , , .
SocketChannel.write()
() , , . TCP- , . , ( 64 ) , ( GB)
, , - .
If you want the data to be sent as quickly as possible, you can try to disable nagle, but most OSs are pretty smart at optimizing and disabling does not make as much difference as used.