thufir

Untitled

Sep 1st, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.81 KB | None | 0 0
  1. thufir@dur:~$
  2. thufir@dur:~$ java -jar NetBeansProjects/SSCCE/dist/SSCCE.jar
  3. print..
  4. ------------------------------------------------------------------------------
  5. * Welcome to THE WEATHER UNDERGROUND telnet service! *
  6. ------------------------------------------------------------------------------
  7. * *
  8. * National Weather Service information provided by Alden Electronics, Inc. *
  9. * and updated each minute as reports come in over our data feed. *
  10. * *
  11. * **Note: If you cannot get past this opening screen, you must use a *
  12. * different version of the "telnet" program--some of the ones for IBM *
  13. * compatible PC's have a bug that prevents proper connection. *
  14. * *
  15. * comments: [email protected] *
  16. ------------------------------------------------------------------------------
  17.  
  18. Press Return to continue:
  19.  
  20. Press Return for menu
  21. or enter 3 letter forecast city code--
  22.  
  23. WEATHER UNDERGROUND MAIN MENU
  24. ******************************
  25. 1) U.S. forecasts and climate data
  26. 2) Canadian forecasts
  27. 3) Current weather observations
  28. 4) Ski conditions
  29. 5) Long-range forecasts
  30. 6) Latest earthquake reports
  31. 7) Severe weather
  32. 8) Hurricane advisories
  33. 9) Weather summary for the past month
  34. 10) International data
  35. 11) Marine forecasts and observations
  36. 12) Ultraviolet light forecast
  37. X) Exit program
  38. C) Change scrolling to screen
  39. H) Help and information for new users
  40. ?) Answers to all your questions
  41. Selection:1
  42. sent 49 cmd 1
  43.  
  44. Not a valid option. Type a number 1 to 12.
  45.  
  46. WEATHER UNDERGROUND MAIN MENU
  47. ******************************
  48. 1) U.S. forecasts and climate data
  49. 2) Canadian forecasts
  50. 3) Current weather observations
  51. 4) Ski conditions
  52. 5) Long-range forecasts
  53. 6) Latest earthquake reports
  54. 7) Severe weather
  55. 8) Hurricane advisories
  56. 9) Weather summary for the past month
  57. 10) International data
  58. 11) Marine forecasts and observations
  59. 12) Ultraviolet light forecast
  60. X) Exit program
  61. C) Change scrolling to screen
  62. H) Help and information for new users
  63. ?) Answers to all your questions
  64. Selection:^Cthufir@dur:~$
  65. thufir@dur:~$
  66. thufir@dur:~$
  67. thufir@dur:~$ cat NetBeansProjects/SSCCE/src/
  68. connection.properties weathertelnet/
  69. thufir@dur:~$ cat NetBeansProjects/SSCCE/src/weathertelnet/Telnet.java
  70. package weathertelnet;
  71.  
  72. import java.io.BufferedReader;
  73. import static java.lang.System.out;
  74. import java.io.IOException;
  75. import java.io.InputStream;
  76. import java.io.InputStreamReader;
  77. import java.net.InetAddress;
  78. import java.net.SocketException;
  79. import java.util.concurrent.ConcurrentLinkedQueue;
  80. import java.util.logging.Logger;
  81. import org.apache.commons.net.telnet.TelnetClient;
  82.  
  83. public final class Telnet {
  84.  
  85. private final static Logger LOG = Logger.getLogger(Telnet.class.getName());
  86. private TelnetClient telnetClient = new TelnetClient();
  87.  
  88. public Telnet() throws SocketException, IOException {
  89. InetAddress host = InetAddress.getByName("rainmaker.wunderground.com");
  90. int port = 3000;
  91. telnetClient.connect(host, port);
  92.  
  93. final InputStream inputStream = telnetClient.getInputStream();
  94. final ConcurrentLinkedQueue<Character> clq = new ConcurrentLinkedQueue();
  95. final StringBuilder sb = new StringBuilder();
  96.  
  97. Thread print = new Thread() {
  98.  
  99. @Override
  100. public void run() {
  101. out.println("print..");
  102. try {
  103. char ch = (char) inputStream.read();
  104. while (255 > ch && ch >= 0) {
  105. clq.add(ch);
  106. out.print(ch);
  107. ch = (char) inputStream.read();
  108. }
  109. } catch (IOException ex) {
  110. out.println("cannot read inputStream:\t" + ex);
  111. }
  112. }
  113. };
  114.  
  115.  
  116. Thread read = new Thread() {
  117.  
  118. @Override
  119. public void run() {
  120. BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  121. try {
  122. do {
  123. String command = in.readLine();
  124. byte[] bytes = command.getBytes();
  125. byte b = 0;
  126. for (int i = 0; i < bytes.length; i++) {
  127. b = bytes[i];
  128. String cmd = new String(bytes);
  129. telnetClient.sendCommand(b);
  130. out.println("sent\t" + b + "\tcmd\t" + cmd);
  131. }
  132. b=10;
  133. telnetClient.sendCommand(b);
  134. } while (true);
  135. } catch (IOException ex) {
  136. }
  137. }
  138. };
  139. print.start();
  140. read.start();
  141. }
  142.  
  143. public static void main(String[] args) throws SocketException, IOException {
  144. new Telnet();
  145. }
  146. }thufir@dur:~$
  147. thufir@dur:~$
Advertisement
Add Comment
Please, Sign In to add comment