thufir

Untitled

Aug 30th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. package weathertelnet;
  2.  
  3. import java.io.Console;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.PrintWriter;
  7. import java.net.SocketException;
  8. import java.util.logging.Level;
  9. import java.util.logging.Logger;
  10. import org.apache.commons.net.telnet.TelnetClient;
  11.  
  12. public final class WeatherTelnet implements Runnable {
  13.  
  14. @Override
  15. public void run() {
  16. new Thread(new Runnable() {
  17.  
  18. @Override
  19. public void run() {
  20. try {
  21. consoleOutput();
  22. } catch (SocketException ex) {
  23. Logger.getLogger(WeatherTelnet.class.getName()).log(Level.SEVERE, null, ex);
  24. } catch (IOException ex) {
  25. Logger.getLogger(WeatherTelnet.class.getName()).log(Level.SEVERE, null, ex);
  26. }
  27. }
  28. }).start();
  29.  
  30.  
  31. new Thread(new Runnable() {
  32.  
  33. @Override
  34. public void run() {
  35. consoleInput();
  36. }
  37. }).start();
  38. }
  39.  
  40. public void consoleInput() {
  41. }
  42.  
  43. public void consoleOutput() throws SocketException, IOException {
  44. TelnetClient tc;
  45. tc = new TelnetClient();
  46. tc.connect("rainmaker.wunderground.com", 3000);
  47.  
  48. InputStream inputStream = tc.getInputStream();
  49.  
  50. char ch = (char) inputStream.read();
  51.  
  52. while (255 > ch && ch >= 0) {
  53. ch = (char) inputStream.read();
  54. PrintWriter foo = c.writer();
  55. foo.print(ch);
  56. foo.flush();
  57. }
  58. }
  59. private Console c;
  60.  
  61. public WeatherTelnet() {
  62. c = System.console();
  63. run();
  64. }
  65.  
  66. public static void main(String[] args) {
  67. new WeatherTelnet();
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment