I am sending message over socket as follows:
socket = new Socket(serverAddr, SERVERPORT);
PrintWriter out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream())),
true);
out.println(str);
But after a while the messages are not delivered, and no exception is thrown (socket.isClosed, socket.isBound - both return true. ). How can i find if socket is still really alive?
Additional Information
Whenever the Server Socket (receiver) restarts, the Client Socket (sender) becomes stale - but there is no exception when messages are sent via this stale Client-Socket (they are simply lost).
So, how do i detect on the sender side that Client Socket is stale, so that i can initiate a reconnect?
Solution
PrintWriter's checkError() may be used to determine write success or failure.