Terminal Emulation?

Valentin Mesaros valentin at info.ucl.ac.be
Thu Jan 16 19:15:57 CET 2003


Robin,

I give you two examples using stdin. A very simple one, and a naive tcp
version which is the sample you sent with some modifications. You can
also work with stdin by using Open.file class (see Mozart doc).

Here is the 1st example. It opens a pipe, sends something on it and
reads the output. Namely, it lists the current directory content. Note
the new line "\n" in the command and in the output stream. I used toAtom
method so that I can easily read the output.

declare
class Shell from Open.pipe end
S={New Shell init(cmd:"/bin/sh")}
{S write( vs: "ls\n")}
{Show {VirtualString.toAtom {S read(list:$)}}}

Here is the 2nd example. What you mainly missed in your sample was the
fact that the accept method opens a new socket for each incoming client
(btw the same happens with the real tcp). So you have to work with the
new created socket in order to communicate with the incoming client.

I let the server be simple so that one can well understand it. It only
treats a command line from only one client (the first one).

functor
import
   Application
   Open
   System
define
   class Shell from Open.pipe end
   class MyPort from Open.socket end
   S
   Port
   Clnt
in
   S = {New Shell init(cmd:"/bin/sh")}
   
   Port={New MyPort init}
   {Port bind( takePort: 7123)}
   {Port listen}
   {Port accept(accepted: Clnt acceptClass: MyPort)}

   {S write(vs:{Clnt read(list:$)})}
   {Clnt write(vs:{S read(list:$)})}

   {Application.exit 0}
end

The client opens a connection to the server, sends a command, gets the
output and closes the connection.

declare
Clnt = {New  Open.socket init}
{Clnt connect(host: "some.computer.address" port: 7123)}
{Clnt write(vs:"ls\n")}
{Show {VirtualString.toAtom {Clnt read(list:$)}}}
{Clnt close}

Valentin

Robin Lee Powell wrote:
> 
> I have tried to right very, very simple Mozart code to basically act as
> a telnet server.  The code is attached.
> 
> It very much doesn't work.  In particular, anything that uses any
> terminal features at all fails, presumably because bash thinks that it
> is talking to STDIN and STDOUT and can't see a terminal.
> 
> Is there any simple way around this?
> 
> Thanks.
> 
> -Robin, who knows almost nothing about terminals at all.
> 
> --
> http://www.digitalkingdom.org/~rlpowell/    ***    I'm a *male* Robin.
> .i le pamoi velru'e zo'u crepu le plibu taxfu
> .i le remoi velru'e zo'u mo .i le cimoi velru'e zo'u ba'e prali .uisai
> http://www.lojban.org/   ***   to sa'a cu'u lei pibyta'u cridrnoma toi
> 
>   ------------------------------------------------------------------------
> 
>    shell.ozName: shell.oz
>            Type: Plain Text (text/plain)
-
Please send submissions to users at mozart-oz.org
and administriva mail to users-request at mozart-oz.org.
The Mozart Oz web site is at http://www.mozart-oz.org/.
Please send bug reports to bugs at mozart-oz.org.





More information about the mozart-users mailing list