thufir

Untitled

Aug 30th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 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:~$
  20. thufir@dur:~$ cat NetBeansProjects/WeatherTelnet/src/weathertelnet/WeatherTelnet.java
  21. package weathertelnet;
  22.  
  23. import java.io.IOException;
  24. import java.io.InputStream;
  25. import java.net.SocketException;
  26. import java.util.logging.Level;
  27. import java.util.logging.Logger;
  28. import org.apache.commons.net.telnet.TelnetClient;
  29. import static java.lang.System.out;
  30.  
  31. public final class WeatherTelnet extends Thread {
  32.  
  33. @Override
  34. public void run() {
  35. new Thread(new Runnable() {
  36.  
  37. @Override
  38. public void run() {
  39. try {
  40. output();
  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.  
  51. public void input() {
  52. }
  53.  
  54. public void output() throws SocketException, IOException {
  55. TelnetClient tc;
  56. tc = new TelnetClient();
  57. tc.connect("rainmaker.wunderground.com", 3000);
  58.  
  59. InputStream inputStream = tc.getInputStream();
  60.  
  61. char ch = (char) inputStream.read();
  62.  
  63. while (255 > ch && ch >= 0) {
  64. ch = (char) inputStream.read();
  65. out.print(ch);
  66. }
  67. }
  68.  
  69. public WeatherTelnet() {
  70. start();
  71. }
  72.  
  73. public static void main(String[] args) {
  74. new WeatherTelnet();
  75. }
  76. }
  77. thufir@dur:~$
  78. thufir@dur:~$
Advertisement
Add Comment
Please, Sign In to add comment