I create a write to socket this way:
socket = new Socket(server, port);
output = new PrintWriter(socket.getOutputStream(),true);
output.println(msg);
I checked the Java documentation about Socket and PrintWriter
classes, but couldn't find any solutions. PrintWriter.println
doesn't seem to return an error or throw and exception when server
closes the socket.
The only way I have managed to check whether the server is alive
is the create a backround thread for reading data in a loop
from server, although server doesn't send anything:
String resp = input.readLine();
if (resp==null) {
System.out.println("null received, break...");
break;
}
This seems to work, although I don't know if there are more
elegant methods available. Any comments?
BR,
Timo
Exactly.
Use a BufferedWriter instead, which will throw an exception if you
attempt to write after the server has closed the connection.
/gordon
--
[ do not send me private copies of your followups ]
g o r d o n . b e a t o n @ e r i c s s o n . c o m