I'm having trouble closing my socket when exiting my Java application. I thought that an easy way to make sure the socket gets closed is to hook it on windowClosing in a Swing JFrame like this:
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
input.close();
output.close();
socket.close();
frame.dispose();
System.exit(0);
}
});
But then I have to handle the IOException that close() creates, and I can't throw it when overriding the event method like that.
How can I make sure that my streams and my socket get closed when the program does?
Thanks.