I'm currently working with sockets in Java.
I have created a listener which will connect to a ServerSocket
. This works perfectly fine. However, if my application may encounter unexpected closure, the sockets won't be closed properly. Upon the next run, this will throw a SocketException: socket closed
on socket = serversocket.accept();
However, by testing with serversocket.isBound()
I've discovered that the serversocket
is in fact bound and therefor not closed. Is there any way for me to determine whether it is possible for me to accept the connection and if not, to clear the socket and accept after this?
Thanks in advance.