Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- thufir@dur:~$
- thufir@dur:~$ java -jar NetBeansProjects/Console/dist/Console.jar
- connecting...
- print..
- makeString..
- java.util.NoSuchElementException
- ------------------------------------------------------------------------------
- * Welcome to THE WEATHER UNDERGROUND telnet service! *
- ------------------------------------------------------------------------------
- * *
- * National Weather Service information provided by Alden Electronics, Inc. *
- * and updated each minute as reports come in over our data feed. *
- * *
- * **Note: If you cannot get past this opening screen, you must use a *
- * different version of the "telnet" program--some of the ones for IBM *
- * compatible PC's have a bug that prevents proper connection. *
- * *
- * comments: [email protected] *
- ------------------------------------------------------------------------------
- Press Return to continue:finally -- waiting for more data..
- java.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.Byte
- finally -- waiting for more data..
- java.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.Byte
- finally -- waiting for more data..
- java.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.Byte
- finally -- waiting for more data..
- java.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.Byte
- finally -- waiting for more data..
- java.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.Byte
- ^Cthufir@dur:~$
- thufir@dur:~$
- thufir@dur:~$ cat NetBeansProjects/Console/src/weathertelnet/TelnetWrapper.java
- package weathertelnet;
- import static java.lang.System.out;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.InetAddress;
- import java.net.SocketException;
- import java.util.concurrent.ConcurrentLinkedQueue;
- import java.util.logging.Logger;
- import org.apache.commons.net.telnet.TelnetClient;
- public class TelnetWrapper {
- private final static Logger LOG = Logger.getLogger(TelnetWrapper.class.getName());
- private TelnetClient telnetClient = new TelnetClient();
- TelnetWrapper(InetAddress host, int port) throws SocketException, IOException {
- out.println("connecting...");
- telnetClient.connect(host, port);
- consoleOutput();
- }
- private void consoleOutput() throws SocketException, IOException {
- final InputStream inputStream = telnetClient.getInputStream();
- final ConcurrentLinkedQueue cq = new ConcurrentLinkedQueue();
- Thread print = new Thread() {
- @Override
- public void run() {
- out.println("print..");
- try {
- char ch = (char) inputStream.read();
- while (255 > ch && ch >= 0) {
- cq.add(ch);
- out.print(ch);
- ch = (char) inputStream.read();
- }
- } catch (IOException ex) {
- }
- }
- };
- Thread makeString = new Thread() {//hmm, takes no arguments
- @Override
- public void run() {
- out.println("makeString..");
- do {
- try {
- byte b = (byte) cq.remove();
- char ch = (char) b;
- } catch (java.util.NoSuchElementException | ClassCastException e) {
- out.println(e);
- try {
- Thread.sleep(1000);
- } catch (InterruptedException ce) {
- }
- } finally {
- out.println("finally -- waiting for more data..");
- try {
- Thread.sleep(1000);
- } catch (InterruptedException ex) {
- }
- }
- } while (true);
- }
- };
- print.start();
- makeString.start();
- }
- private void cmd(String cmd) throws IOException {//haven't tested yet..
- byte[] b = cmd.getBytes();
- System.out.println("streamreader has\t\t" + cmd);
- int l = b.length;
- for (int i = 0; i < l; i++) {
- telnetClient.sendCommand(b[i]);
- }
- }
- }thufir@dur:~$
- thufir@dur:~$
Advertisement
Add Comment
Please, Sign In to add comment