Examples of TelnetClient


Examples of org.apache.commons.net.telnet.TelnetClient

    //
    ctx.start();

    //
    TelnetClient client = new TelnetClient();
    for (int retry_count = 0; retry_count < CLIENT_CONNECT_RETRY_LIMIT; retry_count++) {
      try {
        client.connect("localhost", port);
        break;
      } catch (IOException e) {
        if (retry_count < CLIENT_CONNECT_RETRY_LIMIT) {
          Thread.sleep(CLIENT_CONNECT_RETRY_SLEEP);
        } else {
          throw e;
        }
      }
    }

    //
    this.out = client.getOutputStream();
    this.in = client.getInputStream();
    this.handler = handler;
    this.client = client;
    this.running = true;
  }
View Full Code Here

Examples of org.apache.commons.net.telnet.TelnetClient

            System.err.println(
                "Exception while opening the spy file: "
                + e.getMessage());
        }

        tc = new TelnetClient();

        TerminalTypeOptionHandler ttopt = new TerminalTypeOptionHandler("VT100", false, false, true, false);
        EchoOptionHandler echoopt = new EchoOptionHandler(true, false, true, false);
        SuppressGAOptionHandler gaopt = new SuppressGAOptionHandler(true, true, true, true);
View Full Code Here

Examples of org.apache.commons.net.telnet.TelnetClient

      return;
    else if (password.trim().isEmpty())
      return;
   
    try {
      TelnetClient client = null ;
     

      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;

          if (client == null){
            client = new TelnetClient();
            client.connect(ip);
            receive(client);
            send(client, password);
            receive(client);
          }
         
          send(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);

        }
      }
      if (client != null)
        client.disconnect();
    } catch (Exception e) {
      logger.warn("Could not get item state ", e);
    }

  }
View Full Code Here

Examples of org.apache.commons.net.telnet.TelnetClient

    private Command command;

    @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:
        send(client, password);
        receive(client); // welcome text
        send(client, cmdString);
        Thread.sleep(1000L); // response not needed - may be interesting
                    // for reading status
        client.disconnect();

      } catch (Exception e) {
        logger.warn("Error processing command", e);
      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.