01: package kawa;
02:
03: import gnu.expr.*;
04: import gnu.mapping.*;
05: import gnu.text.*;
06:
07: public class TelnetRepl extends Procedure0 {
08: // close when finished.
09: java.net.Socket socket;
10:
11: Language language;
12:
13: public TelnetRepl(Language language, java.net.Socket socket) {
14: this .language = language;
15: this .socket = socket;
16: }
17:
18: public Object apply0() {
19: try {
20: Shell.run(language, Environment.getCurrent());
21: return Values.empty;
22: } finally {
23: try {
24: socket.close();
25: } catch (java.io.IOException ex) {
26: }
27: }
28: }
29:
30: /** Run a Kawa repl as a telnet server.
31: @param client A client that has connected to us,
32: and that wants to use the telnet protocol to talk to a
33: Scheme read-eval-print-loop. */
34: public static void serve(Language language, java.net.Socket client)
35: throws java.io.IOException {
36: Telnet conn = new Telnet(client, true);
37: java.io.OutputStream sout = conn.getOutputStream();
38: java.io.InputStream sin = conn.getInputStream();
39: OutPort out = new OutPort(sout, FilePath.valueOf("/dev/stdout"));
40: TtyInPort in = new TtyInPort(sin, FilePath
41: .valueOf("/dev/stdin"), out);
42: /*
43: conn.request(Telnet.DO, Telnet.EOF);
44: conn.request(Telnet.DO, Telnet.NAWS);
45: conn.request(Telnet.DO, Telnet.TTYPE);
46: conn.request(Telnet.DO, Telnet.LINEMODE);
47: */
48:
49: Thread thread = new Future(new TelnetRepl(language, client),
50: Environment.getCurrent(), in, out, out);
51: thread.start();
52: }
53: }
|