I want to know how I can catch the "connection excluded" exception in Java when I use socket. (what happens if the server is down or not responding).
Below is how I implemented so far.
try { sockfd = new Socket(host.getHostName(),heart_port); sockfd.setReuseAddress(true); BufferedReader message = new BufferedReader(new InputStreamReader ( sockfd.getInputStream() ) ); message.close(); sockfd.close(); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
source share