thufir

Untitled

Aug 30th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 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 org.apache.commons.net.telnet.TelnetClient;
  9.  
  10. public final class WeatherTelnet implements Runnable {
  11.  
  12. private Console c;
  13.  
  14. @Override
  15. public void run() {
  16.  
  17.  
  18. new Thread(new Runnable() {
  19.  
  20. @Override
  21. public void run() {
  22. consoleInput();
  23. }
  24. }).start();
  25. }
  26.  
  27. public void consoleInput() {
  28. do {
  29. String s = c.readLine(); //this should only execute when triggered
  30. PrintWriter pw = c.writer();
  31. pw.println("you entered ");
  32. pw.println(s);
  33. pw.flush();
  34. } while (true); //how do I wait *until* a line is entered.
  35. }
  36.  
  37. public void consoleOutput() throws SocketException, IOException {
  38. TelnetClient tc;
  39. tc = new TelnetClient();
  40. tc.connect("rainmaker.wunderground.com", 3000);
  41.  
  42. InputStream inputStream = tc.getInputStream();
  43.  
  44. char ch = (char) inputStream.read();
  45.  
  46. while (255 > ch && ch >= 0) {
  47. PrintWriter foo = c.writer();
  48. foo.print(ch);
  49. foo.flush();
  50. ch = (char) inputStream.read();
  51. }
  52. }
  53.  
  54. public WeatherTelnet() {
  55. c = System.console();
  56. run();
  57. }
  58.  
  59. public static void main(String[] args) {
  60. new WeatherTelnet();
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment