Reference to the Question I asked before, the socket closing need some times to operate:
Why it warns me the socket is closed when I quit the programme?
providerSocket.close();
Can I ask it to run several code when I close the socket? Thanks.
I ran across this problem with
SocketChannels, and as far as I can tell (and as far as Stack Overflow can tell) there’s no supported way to do this with the JDK. However, I didn’t let that stop me. With proper encapsulation you can do something like this:This isn’t as flexible as I would like and that’s why I’m still leaving my question unanswered, but it might be a good solution for you. Of course, coming up with a better name than
SocketWrappermight be a good idea.