// Telnet.java // A Telnet window as applet // usage // IP-Address = Dotted 4 byte standard address // Port = Standard port number, e.g. 23 for Telnet port // Example: // Author: Fritz Hohl (hohl@hermes.informatik.uni-stuttgart.de) // System: Java Alpha release // Date: 19.5.95 import awt.*; import browser.NameServer; import java.io.InputStream; import java.util.Hashtable; import net.www.html.*; import net.Socket; import browser.Applet; public class Telnet extends Applet implements Runnable { String ipadresse; Integer port; Socket dose; String text[] = new String[25]; public int zeile = 0; public int spalte = 0; // Transcript alpha; private Thread kicker; private Integer bip; private Ping watchdog; // ---------------------------------------------------- public void crlf() { spalte = 0; zeile++; if (zeile > 24) { for (int i = 0; i < 24; i++) { text[i] = text[i + 1]; } zeile = 24; text[24] = ""; } } // ---------------------------------------------------- public synchronized void show1(String einString) { // alpha.show(zeile); if (spalte < 80) { text[zeile] = text[zeile].concat(einString); spalte += 1; } else { spalte = 0; if (zeile == 24) { // alpha.show("Scroll on"); for (int i = 0; i < 24; i++) { text[i] = text[i + 1]; } // alpha.show("Scroll off"); text[24] = einString; } else { zeile += 1; text[zeile] = einString; } } } // ---------------------------------------------------- public void show(String einString) { for (int i = 0; i < einString.length(); i++) { show1(einString.substring(i, i + 1)); } } // ---------------------------------------------------- public void init() { resize(640,400); String at = getAttribute("alg"); if (at == null) { at = "0.0.0.0"; } ipadresse = at; at = getAttribute("alh"); if (at == null) { at = "0"; } port = port.valueOf(at,10); dose = new Socket(ipadresse,port.intValue()); // alpha = Transcript.get(); for (int i = 0; i < 25; i++) { text[i] = ""; } show("Verbindung hergestellt."); bip = new Integer(0); watchdog = new Ping(this); } // ---------------------------------------------------- public int setzero() { int tmp; synchronize (bip) { tmp = bip.intValue(); bip = new Integer(0); } return(tmp); } // ---------------------------------------------------- public int next() { synchronize (bip) { bip = new Integer(bip.intValue() + 1); // alpha.show(bip.intValue()); } return(dose.inputStream.read()); } // ---------------------------------------------------- public void paint(Graphics g) { g.clearRect(0,0,639,399); g.drawRect(0,0,639,399); for (int i = 0; i < 25; i++) { g.drawString(text[i],2, i*16 + 16); } } // ---------------------------------------------------- public String intToString(int zeichen) { byte eins[] = new byte[1]; //alpha.show(zeichen); eins[0] = (byte)zeichen; return(new String(eins,0)); } // ---------------------------------------------------- public void keyDown( int key ) { dose.outputStream.write(key); } // ---------------------------------------------------- public synchronized void mouseUp( int x, int y) { getFocus(); // um Tastaturevents verarbeiten zu koennen if (kicker == null || !kicker.isAlive()) { kicker = new Thread(this); kicker.start(); watchdog.start(); } } // ---------------------------------------------------- public synchronized void stop() { if (kicker != null) { try { kicker.stop(); } catch (IllegalStateException e) { // ignore this exception } kicker = null; } } // ---------------------------------------------------- public void run() { int key = 0; while (key != -1) { key = next(); if (key == 13) { key = next(); crlf(); key = next(); show1(intToString(key)); } else { if (key == -1) { show("Verbindung beendet."); } else { if (key == 255) { // alpha.show("IAC"); key = next(); if (key == 253) { // alpha.show("DO"); key = next(); // alpha.show(key); // No negotiations with the enemy :-) dose.outputStream.write(255); dose.outputStream.write(252); dose.outputStream.write(key); } if (key == 254) { // alpha.show("DON'T"); key = next(); // alpha.show(key); // No negotiations with the enemy :-) dose.outputStream.write(255); dose.outputStream.write(252); dose.outputStream.write(key); } } else { show1(intToString(key)); } } } } } // ---------------------------------------------------- }