Well, I came up with this this approach to get all input from the Telnet
server:
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:~$ cat
NetBeansProjects/WeatherTelnet/src/weathertelnet/WeatherTelnet.java
package weathertelnet;
import java.io.Console;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.SocketException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.net.telnet.TelnetClient;
public final class WeatherTelnet implements Runnable {
@Override
public void run() {
new Thread(new Runnable() {
@Override
public void run() {
try {
consoleOutput();
} 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();
new Thread(new Runnable() {
@Override
public void run() {
consoleInput();
}
}).start();
}
public void consoleInput() {
}
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) {
ch = (char) inputStream.read();
PrintWriter foo = c.writer();
foo.print(ch);
foo.flush();
}
}
private Console c;
public WeatherTelnet() {
c = System.console();
run();
}
public static void main(String[] args) {
new WeatherTelnet();
}
}
thufir@dur:~$
thufir@dur:~$
see also:
http://www.mudbytes.net/index.php?a=topic&t=4372
The trick is to capture *all* input as it arrives, even without a CRLF
at the end.
-Thufir
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]