Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- thufir@dur:~/NetBeansProjects/TelnetConsole$
- thufir@dur:~/NetBeansProjects/TelnetConsole$ java -jar dist/TelnetConsole.jar
- noSuchElementException...
- command
- no command sent
- noSuchElementException...
- command
- no command sent
- 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:
- command
- byte 10
- no command sent
- noSuchElementException...
- command
- no command sent
- noSuchElementException...
- command
- no command sent
- anoSuchElementException...
- command
- no command sent
- your command a
- command a
- byte 97
- no command sent a
- noSuchElementException...
- command
- no command sent
- b
- your command b
- command b
- byte 98
- no command sent b
- noSuchElementException...
- command
- no command sent
- your command
- command
- no command sent
- noSuchElementException...
- command
- no command sent
- noSuchElementException...
- command
- no command sent
- ^Cthufir@dur:~/NetBeansProjects/TelnetConsole$
- thufir@dur:~/NetBeansProjects/TelnetConsole$
- thufir@dur:~/NetBeansProjects/TelnetConsole$
- package telnet;
- import static java.lang.System.out;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.net.InetAddress;
- import java.net.SocketException;
- import java.util.Observable;
- import java.util.Observer;
- import java.util.Properties;
- import java.util.concurrent.ConcurrentLinkedQueue;
- import org.apache.commons.net.telnet.TelnetClient;
- public final class Controller implements Observer {
- private TelnetClient telnetClient = new TelnetClient();
- private InputStreamReader serverReader = new InputStreamReader();
- private ConsoleReader consoleReader = new ConsoleReader();
- private QueueWatcher dataProcessor = new QueueWatcher();
- private Triggers triggers = new Triggers();
- private final ConcurrentLinkedQueue<Character> telnetData = new ConcurrentLinkedQueue();
- private OutputStream outputStream = telnetClient.getOutputStream();
- public void readPrintParse(final InputStream inputStream) throws SocketException, IOException {
- serverReader.print(inputStream, telnetData);
- serverReader.addObserver(this);
- consoleReader.read();
- consoleReader.addObserver(this);
- dataProcessor.read(telnetData);
- dataProcessor.addObserver(this);
- triggers.addObserver(this);
- }
- private void sendCommand(String command) {
- out.println("command\t\t" + command);
- try {
- byte[] bytes = command.getBytes();
- for (int i = 0; i < bytes.length; i++) {
- out.println("byte\t" + bytes[i]);
- }
- outputStream.write(bytes);
- outputStream.flush();
- } catch (IOException | NullPointerException ex) {
- out.println("no command sent\t" + command);
- }
- }
- @Override
- public void update(Observable o, Object arg) {
- String command = "help";
- if (o instanceof QueueWatcher) {
- String data = dataProcessor.getFinalData();
- out.println("noSuchElementException...\n" + data);
- command = triggers.parse(data);
- sendCommand(command);
- }
- if (o instanceof ConsoleReader) {
- command = consoleReader.getCommand();
- out.println("your command\t\t" + command);
- sendCommand(command);
- }
- }
- public Controller() throws SocketException, IOException {
- Properties props = PropertiesReader.getProps();
- InetAddress host = InetAddress.getByName(props.getProperty("host"));
- int port = Integer.parseInt(props.getProperty("port"));
- telnetClient.connect(host, port);
- readPrintParse(telnetClient.getInputStream());
- }
- public static void main(String[] args) throws SocketException, IOException {
- new Controller();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment