2 /* "In case you would like to use the packages as libraries please
3 * apply the GNU Library General Public License as documented in the
4 * file COPYING.LIB." (from Telnet/Documentation/index.html)
7 /* IOtest.java -- An example how to use the TelnetIO class
9 * Author: Matthias L. Jugel
11 * Usage: compile with javac IOtest.java
12 * run program with java IOtest
14 * This is not an applet, but the idea might be used in one.
17 import java.util.Vector;
19 import de.mud.telnet.socket.*;
22 * IOtest -- a test class for telnet i/o
24 * @version $Id: IOtest.java,v 1.1.1.1 1997/03/05 13:35:16 leo Exp $
25 * @author Matthias L. Jugel
29 // create a new telnet io instance
30 static TelnetIO tio = new TelnetIO();
32 // skip any received data until the prompt appears
33 private static void wait(String prompt)
37 try { tmp = new String(tio.receive(), 0); }
38 catch(IOException e) { e.printStackTrace(); }
39 System.out.println(tmp);
40 } while(tmp.indexOf(prompt) == -1);
43 // send a string to the remote host, since TelnetIO needs a byte buffer
44 // we have to convert the string first
45 private static void send(String str)
47 byte[] buf = new byte[str.length()];
48 str.getBytes(0, str.length(), buf, 0);
49 try { tio.send(buf); } catch(IOException e) {}
52 // this function is called when running the class with java IOtest
53 // looks very much like a modem login script ;-)
54 public static void main(String args[])
57 tio.connect("localhost");
59 send("<YOUR LOGIN NAME>\r");
61 send("<YOUR PASSWORD>\r");
62 wait("<YOUR SHELL PROMPT>");
63 send("touch /tmp/THIS_WAS_AN_APPLET\r");
65 } catch(IOException e) { e.printStackTrace(); }