java - How to close a non blocking socket channel properly? -


i'm writing server program using java non-blocking socketchannel. want send reply message , close channel, following code.

however, close() method interrupts write() method, java.nio.channels.closedchannelexception , message not sent.

i can pop thread , wait 1-2 seconds before closing channel, feel it's wasteful making thread.

what proper way close socketchannel while there pending operations?

string msg = "wrong password!"; channel.write(bytebuffer.wrap(msg.getbytes())); channel.close(); 

channel.socket().setsolinger(true, max_seconds_for_output_to_drain);

see info on linger option. mentioned, cause close() block max_seconds_for_output_to_drain seconds.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -