Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- thufir@dur:~$
- thufir@dur:~$ java -jar NetBeansProjects/SSCCE/dist/SSCCE.jar
- print..
- ------------------------------------------------------------------------------
- * 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:
- Press Return for menu
- or enter 3 letter forecast city code--
- WEATHER UNDERGROUND MAIN MENU
- ******************************
- 1) U.S. forecasts and climate data
- 2) Canadian forecasts
- 3) Current weather observations
- 4) Ski conditions
- 5) Long-range forecasts
- 6) Latest earthquake reports
- 7) Severe weather
- 8) Hurricane advisories
- 9) Weather summary for the past month
- 10) International data
- 11) Marine forecasts and observations
- 12) Ultraviolet light forecast
- X) Exit program
- C) Change scrolling to screen
- H) Help and information for new users
- ?) Answers to all your questions
- Selection:1
- sent 49 cmd 1
- Not a valid option. Type a number 1 to 12.
- WEATHER UNDERGROUND MAIN MENU
- ******************************
- 1) U.S. forecasts and climate data
- 2) Canadian forecasts
- 3) Current weather observations
- 4) Ski conditions
- 5) Long-range forecasts
- 6) Latest earthquake reports
- 7) Severe weather
- 8) Hurricane advisories
- 9) Weather summary for the past month
- 10) International data
- 11) Marine forecasts and observations
- 12) Ultraviolet light forecast
- X) Exit program
- C) Change scrolling to screen
- H) Help and information for new users
- ?) Answers to all your questions
- Selection:^Cthufir@dur:~$
- thufir@dur:~$
- thufir@dur:~$
- thufir@dur:~$ cat NetBeansProjects/SSCCE/src/
- connection.properties weathertelnet/
- thufir@dur:~$ cat NetBeansProjects/SSCCE/src/weathertelnet/Telnet.java
- package weathertelnet;
- import java.io.BufferedReader;
- import static java.lang.System.out;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- 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 final class Telnet {
- private final static Logger LOG = Logger.getLogger(Telnet.class.getName());
- private TelnetClient telnetClient = new TelnetClient();
- public Telnet() throws SocketException, IOException {
- InetAddress host = InetAddress.getByName("rainmaker.wunderground.com");
- int port = 3000;
- telnetClient.connect(host, port);
- final InputStream inputStream = telnetClient.getInputStream();
- final ConcurrentLinkedQueue<Character> clq = new ConcurrentLinkedQueue();
- final StringBuilder sb = new StringBuilder();
- Thread print = new Thread() {
- @Override
- public void run() {
- out.println("print..");
- try {
- char ch = (char) inputStream.read();
- while (255 > ch && ch >= 0) {
- clq.add(ch);
- out.print(ch);
- ch = (char) inputStream.read();
- }
- } catch (IOException ex) {
- out.println("cannot read inputStream:\t" + ex);
- }
- }
- };
- Thread read = new Thread() {
- @Override
- public void run() {
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- try {
- do {
- String command = in.readLine();
- byte[] bytes = command.getBytes();
- byte b = 0;
- for (int i = 0; i < bytes.length; i++) {
- b = bytes[i];
- String cmd = new String(bytes);
- telnetClient.sendCommand(b);
- out.println("sent\t" + b + "\tcmd\t" + cmd);
- }
- b=10;
- telnetClient.sendCommand(b);
- } while (true);
- } catch (IOException ex) {
- }
- }
- };
- print.start();
- read.start();
- }
- public static void main(String[] args) throws SocketException, IOException {
- new Telnet();
- }
- }thufir@dur:~$
- thufir@dur:~$
Advertisement
Add Comment
Please, Sign In to add comment