thufir

thread sends ch to another thread

Aug 31st, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. package weathertelnet;
  2.  
  3. import static java.lang.System.out;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.net.InetAddress;
  7. import java.net.SocketException;
  8. import java.util.logging.Logger;
  9. import org.apache.commons.net.telnet.TelnetClient;
  10.  
  11. public class TelnetWrapper {
  12.  
  13.     private final static Logger LOG = Logger.getLogger(TelnetWrapper.class.getName());
  14.     private TelnetClient telnetClient = new TelnetClient();
  15.  
  16.     TelnetWrapper(InetAddress host, int port) throws SocketException, IOException {
  17.         out.println("connecting...");
  18.         telnetClient.connect(host, port);
  19.         consoleOutput();
  20.  
  21.     }
  22.  
  23.     private void consoleOutput() throws SocketException, IOException {
  24.         final InputStream inputStream = telnetClient.getInputStream();
  25.  
  26.         Thread print = new Thread() {
  27.  
  28.             @Override
  29.             public void run() {
  30.                 out.println("print..");
  31.                 try {
  32.                     char ch = (char) inputStream.read();
  33.                     while (255 > ch && ch >= 0) {
  34.                         out.print(ch);
  35.                         ch = (char) inputStream.read();
  36.                         //send the ch to the makeString thread..
  37.                     }
  38.                 } catch (IOException ex) {
  39.                 }
  40.             }
  41.         };
  42.  
  43.         Thread makeString = new Thread() {//hmm, takes no arguments
  44.  
  45.             @Override
  46.             public void run() {
  47.                 out.println("makeString..");
  48.                 //use StringBuilder to add each char as it arrives
  49.             }
  50.         };
  51.         print.start();
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment