Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package weathertelnet;
- import java.io.Console;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.PrintWriter;
- import java.net.SocketException;
- import org.apache.commons.net.telnet.TelnetClient;
- public final class WeatherTelnet implements Runnable {
- private Console c;
- @Override
- public void run() {
- new Thread(new Runnable() {
- @Override
- public void run() {
- consoleInput();
- }
- }).start();
- }
- public void consoleInput() {
- do {
- String s = c.readLine(); //this should only execute when triggered
- PrintWriter pw = c.writer();
- pw.println("you entered ");
- pw.println(s);
- pw.flush();
- } while (true); //how do I wait *until* a line is entered.
- }
- public void consoleOutput() throws SocketException, IOException {
- TelnetClient tc;
- tc = new TelnetClient();
- tc.connect("rainmaker.wunderground.com", 3000);
- InputStream inputStream = tc.getInputStream();
- char ch = (char) inputStream.read();
- while (255 > ch && ch >= 0) {
- PrintWriter foo = c.writer();
- foo.print(ch);
- foo.flush();
- ch = (char) inputStream.read();
- }
- }
- public WeatherTelnet() {
- c = System.console();
- run();
- }
- public static void main(String[] args) {
- new WeatherTelnet();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment