private void disconnect() { try { telnet.disconnect(); } catch (IOException e) { log.error("Error occured while telnet disconnection " + e); } }
public void disconnect() { try { telnet.disconnect(); } catch (Exception e) { logger.error("error while disconnecting telnet client"); } }
/** 关闭连接 */ public void distinct() { try { if (telnet != null && !telnet.isConnected()) telnet.disconnect(); } catch (IOException e) { e.printStackTrace(); } }
@Override protected void execute() { try { TelnetClient client = new TelnetClient(); client.connect(ip); receive(client); sendLine(client, password); receive(client); for (FritzboxBindingProvider provider : providers) { for (String item : provider.getItemNames()) { String query = null; String type = provider.getType(item); if (queryMap.containsKey(type)) { query = queryMap.get(type); } else if (type.startsWith("tam")) { query = "ctlmgr_ctl r tam settings/" + type.toUpperCase() + "/Active"; } else if (type.startsWith("query")) { query = type.substring(type.indexOf(":") + 1).trim(); } else continue; sendLine(client, query); String answer = receive(client); String[] lines = answer.split("\r\n"); if (lines.length >= 2) { answer = lines[1].trim(); } Class<? extends Item> itemType = provider.getItemType(item); org.openhab.core.types.State state = null; if (itemType.isAssignableFrom(SwitchItem.class)) { if (answer.equals("1")) state = OnOffType.ON; else state = OnOffType.OFF; } else if (itemType.isAssignableFrom(NumberItem.class)) { state = new DecimalType(answer); } else if (itemType.isAssignableFrom(StringItem.class)) { state = new StringType(answer); } if (state != null) eventPublisher.postUpdate(item, state); } } client.disconnect(); } catch (Exception e) { logger.warn("Could not get item state", e.toString()); } }
private void closeConnection() throws IOException { logger.debug("closeConnection()"); m_eventBus.post(new StateChangeEvent(this, EventType.LOST_CONNECTION)); m_TelnetState = TelnetState.DISCONNECTED; m_LoginState = LoginState.NO; m_StokerState = StokerCmdState.UNKNOWN; if (m_ReaderThread != null) m_ReaderThread.interrupt(); if (m_Telnet .isConnected()) // this is to get around a null Pointer exception in the disconnect if the // stoker is lost m_Telnet.disconnect(); }
@Override public void run() { try { TelnetClient client = new TelnetClient(); client.connect(ip); int state = 0; if (command == OnOffType.ON) state = 1; String cmdString = null; if (commandMap.containsKey(type)) { cmdString = commandMap.get(type) + " " + state; } else if (type.startsWith("tam")) { cmdString = "ctlmgr_ctl w tam settings/" + type.toUpperCase() + "/Active " + state; } else if (type.startsWith("cmd")) { int on = type.indexOf("ON="); int off = type.indexOf("OFF="); if (state == 0) { cmdString = type.substring(off + 4, on < off ? type.length() : on); } else { cmdString = type.substring(on + 3, off < on ? type.length() : off); } cmdString = cmdString.trim(); } /* * This is a approach with receive/send in serial way. This * could be done via a sperate thread but for just sending one * command it is not necessary */ receive(client); // password: sendLine(client, password); receive(client); // welcome text sendLine(client, cmdString); Thread.sleep(1000L); // response not needed - may be interesting // for reading status client.disconnect(); } catch (Exception e) { logger.warn("Could not send command", e.toString()); } }
public static final void main(String[] args) { TelnetClient telnet; telnet = new TelnetClient(); try { telnet.connect("rainmaker.wunderground.com", 3000); } catch (IOException e) { e.printStackTrace(); System.exit(1); } IOUtil.readWrite(telnet.getInputStream(), telnet.getOutputStream(), System.in, System.out); try { telnet.disconnect(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } System.exit(0); }
@Override public void disconnect() { loggedIn = false; try { log.info("Disconnecting from teclnet client"); if (expector != null) { expector.close(); } } catch (Exception e) { log.warn("Error while closing telnet session", e); } finally { expector = null; } try { if (client != null) { client.disconnect(); } } catch (Exception e) { log.warn("Error while closing telnet session", e); } finally { client = null; } }
private static void closeTelnetSession() throws IOException, InterruptedException { Thread.sleep(2000); telnet.disconnect(); }