Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- thufir@dur:~$
- thufir@dur:~$ java -jar NetBeansProjects/WeatherTelnet/dist/WeatherTelnet.jar
- -----------------------------------------------------------------------------
- * Welcome to THE WEATHER UNDERGROUND telnet service! *
- ------------------------------------------------------------------------------
- * *
- * National Weather Service information provided by Alden Electronics, Inc. *
- * and updated each minute as reports come in over our data feed. *
- * *
- * **Note: If you cannot get past this opening screen, you must use a *
- * different version of the "telnet" program--some of the ones for IBM *
- * compatible PC's have a bug that prevents proper connection. *
- * *
- * comments: [email protected] *
- ------------------------------------------------------------------------------
- Press Return to continue:
- ^Cthufir@dur:~$
- thufir@dur:~$
- thufir@dur:~$ cat NetBeansProjects/WeatherTelnet/src/weathertelnet/WeatherTelnet.java
- package weathertelnet;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.SocketException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import org.apache.commons.net.telnet.TelnetClient;
- import static java.lang.System.out;
- public final class WeatherTelnet extends Thread {
- @Override
- public void run() {
- new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- output();
- } catch (SocketException ex) {
- Logger.getLogger(WeatherTelnet.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IOException ex) {
- Logger.getLogger(WeatherTelnet.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }).start();
- }
- public void input() {
- }
- public void output() 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) {
- ch = (char) inputStream.read();
- out.print(ch);
- }
- }
- public WeatherTelnet() {
- start();
- }
- public static void main(String[] args) {
- new WeatherTelnet();
- }
- }
- thufir@dur:~$
- thufir@dur:~$
Advertisement
Add Comment
Please, Sign In to add comment