added applet mode, terminal window
[fleet.git] / src / de / mud / telnet / IOtest.java
1 package de.mud.telnet;
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)
5  */
6
7 /* IOtest.java -- An example how to use the TelnetIO class
8  * --
9  * Author: Matthias L. Jugel
10  *
11  * Usage: compile with javac IOtest.java
12  *        run program with java IOtest
13  *
14  * This is not an applet, but the idea might be used in one. 
15  */
16
17 import java.util.Vector;
18 import java.io.*;
19 import de.mud.telnet.socket.*;
20
21 /**
22  * IOtest -- a test class for telnet i/o
23  * --
24  * @version     $Id: IOtest.java,v 1.1.1.1 1997/03/05 13:35:16 leo Exp $
25  * @author      Matthias L. Jugel
26  */
27 class IOtest {
28
29   // create a new telnet io instance
30   static TelnetIO tio = new TelnetIO();
31
32   // skip any received data until the prompt appears
33   private static void wait(String prompt)
34   {
35     String tmp = "";
36     do {
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);
41   }
42
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)
46   {
47     byte[] buf = new byte[str.length()];
48     str.getBytes(0, str.length(), buf, 0);
49     try { tio.send(buf); } catch(IOException e) {}
50   }
51
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[])
55   {
56     try {
57       tio.connect("localhost");
58       wait("login:");
59       send("<YOUR LOGIN NAME>\r");
60       wait("Password:");
61       send("<YOUR PASSWORD>\r");
62       wait("<YOUR SHELL PROMPT>");
63       send("touch /tmp/THIS_WAS_AN_APPLET\r");
64       tio.disconnect();
65     } catch(IOException e) { e.printStackTrace(); }
66   }
67 }