SocketChannel flush before close

Y

yarivvv

Hi,

I wrote a simple http server using java.nio. I've run into a problem
where occasionally, calling close() on the SocketChannel closes the
socket prematurely, before all the response bytes have been sent to the
client. Is there a way to ensure that the SocketChannel flushes before
closing?

Thanks
Yariv
 
E

Esmond Pitt

yarivvv said:
Hi,

I wrote a simple http server using java.nio. I've run into a problem
where occasionally, calling close() on the SocketChannel closes the
socket prematurely, before all the response bytes have been sent to the
client. Is there a way to ensure that the SocketChannel flushes before
closing?

There is no such thing as flush() in a Channel. The only way bytes can
get lost is if you lose them: it is up to you to check the return value
from SocketChannel.write() and make sure that all the bytes you intended
to write were written.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top