I have a socket program which is sending text data via PrintWriter(out.write(String str)), on the other side BufferedReader(in.readLine()) is receiving this.
I want to secure my program with some kind 'timeout' if one of clients breaks the connection, but I tested it and during work, when client will be turned off, server is still sending data and there is no interruption nor socket closing.
Same for client, I want to break connection and display info for example "server is not working". How I can handle this ?
// Server
out = new PrintWriter( sock.getOutputStream());
while( true ) {
this.out.write("Hello");
this.out.flush();
}
// Client
in = new BufferedReader( new InputStreamReader( sock.getInputStream()));
while (true) {
in.readLine();
}