List of usage examples for java.net NoRouteToHostException toString
public String toString()
From source file:org.openhab.binding.yeelight.internal.YeelightBinding.java
private String sendYeelightCommand(String location, String action, Object[] params) { int index = location.indexOf(":"); Socket clientSocket = null;//from w w w.j ava 2 s .c om try { String ip = location.substring(0, index); int port = Integer.parseInt(location.substring(index + 1)); clientSocket = new Socket(ip, port); DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream()); BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); String sentence = "{\"id\":" + msgid++ + ",\"method\":\"" + action + "\",\"params\":[" + getProperties(params) + "]}\r\n"; logger.debug("Sending sentence: {}", sentence); outToServer.writeBytes(sentence); return inFromServer.readLine(); } catch (NoRouteToHostException e) { logger.debug("Location {} is probably offline", location); if (action.equals(GET_PROP)) { //update switches if not found location to OFF state for (Object item : getOnSwitchItems(location)) { eventPublisher.postUpdate((String) item, OnOffType.OFF); } } } catch (IOException e) { logger.error(e.toString()); } finally { if (clientSocket != null) try { clientSocket.close(); } catch (IOException e) { //silence } } return null; }