thufir

Untitled

Aug 30th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. thufir@dur:~$
  2. thufir@dur:~$ java -jar NetBeansProjects/WeatherTelnet/dist/WeatherTelnet.jar
  3. -----------------------------------------------------------------------------
  4. * Welcome to THE WEATHER UNDERGROUND telnet service! *
  5. ------------------------------------------------------------------------------
  6. * *
  7. * National Weather Service information provided by Alden Electronics, Inc. *
  8. * and updated each minute as reports come in over our data feed. *
  9. * *
  10. * **Note: If you cannot get past this opening screen, you must use a *
  11. * different version of the "telnet" program--some of the ones for IBM *
  12. * compatible PC's have a bug that prevents proper connection. *
  13. * *
  14. * comments: [email protected] *
  15. ------------------------------------------------------------------------------
  16.  
  17. Press Return to continue:
  18. ^Cthufir@dur:~$
  19. thufir@dur:~$ cat NetBeansProjects/WeatherTelnet/src/weathertelnet/WeatherTelnet.java
  20. package weathertelnet;
  21.  
  22. import java.io.Console;
  23. import java.io.IOException;
  24. import java.io.InputStream;
  25. import java.io.PrintWriter;
  26. import java.net.SocketException;
  27. import java.util.logging.Level;
  28. import java.util.logging.Logger;
  29. import org.apache.commons.net.telnet.TelnetClient;
  30.  
  31. public final class WeatherTelnet implements Runnable {
  32.  
  33. @Override
  34. public void run() {
  35. new Thread(new Runnable() {
  36.  
  37. @Override
  38. public void run() {
  39. try {
  40. consoleOutput();
  41. } catch (SocketException ex) {
  42. Logger.getLogger(WeatherTelnet.class.getName()).log(Level.SEVERE, null, ex);
  43. } catch (IOException ex) {
  44. Logger.getLogger(WeatherTelnet.class.getName()).log(Level.SEVERE, null, ex);
  45. }
  46. }
  47. }).start();
  48.  
  49.  
  50. new Thread(new Runnable() {
  51.  
  52. @Override
  53. public void run() {
  54. consoleInput();
  55. }
  56. }).start();
  57. }
  58.  
  59. public void consoleInput() {
  60. }
  61.  
  62. public void consoleOutput() throws SocketException, IOException {
  63. TelnetClient tc;
  64. tc = new TelnetClient();
  65. tc.connect("rainmaker.wunderground.com", 3000);
  66.  
  67. InputStream inputStream = tc.getInputStream();
  68.  
  69. char ch = (char) inputStream.read();
  70.  
  71. while (255 > ch && ch >= 0) {
  72. ch = (char) inputStream.read();
  73. PrintWriter foo = c.writer();
  74. foo.print(ch);
  75. foo.flush();
  76. }
  77. }
  78. private Console c;
  79.  
  80. public WeatherTelnet() {
  81. c = System.console();
  82. run();
  83. }
  84.  
  85. public static void main(String[] args) {
  86. new WeatherTelnet();
  87. }
  88. }
  89. thufir@dur:~$
  90. thufir@dur:~$
Advertisement
Add Comment
Please, Sign In to add comment