Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package weathertelnet;
- import static java.lang.System.out;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.InetAddress;
- import java.net.SocketException;
- import java.util.logging.Logger;
- import org.apache.commons.net.telnet.TelnetClient;
- public class TelnetWrapper {
- private final static Logger LOG = Logger.getLogger(TelnetWrapper.class.getName());
- private TelnetClient telnetClient = new TelnetClient();
- TelnetWrapper(InetAddress host, int port) throws SocketException, IOException {
- out.println("connecting...");
- telnetClient.connect(host, port);
- consoleOutput();
- }
- private void consoleOutput() throws SocketException, IOException {
- final InputStream inputStream = telnetClient.getInputStream();
- Thread print = new Thread() {
- @Override
- public void run() {
- out.println("print..");
- try {
- char ch = (char) inputStream.read();
- while (255 > ch && ch >= 0) {
- out.print(ch);
- ch = (char) inputStream.read();
- //send the ch to the makeString thread..
- }
- } catch (IOException ex) {
- }
- }
- };
- Thread makeString = new Thread() {//hmm, takes no arguments
- @Override
- public void run() {
- out.println("makeString..");
- //use StringBuilder to add each char as it arrives
- }
- };
- print.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment