Go to the first, previous, next, last section, table of contents.


"read-only-1|"

The last two examples were readOnly servers: Muq was reading from them but not writing to them. Here we provide simple example of a write-only server. Write-only servers might be useful in practice for controlling an output device (such as driving an output MIDI music port, say) or perhaps for generating email, say as part of a registration system.

To keep this example simple, our example server will merely accept text, convert it to upper case, and print it on the console. (A simple variant might be used to provide access to the syslogd daemon from within the Muq.)

In muq/srv/ create a file read-only-1 with contents

#!/usr/local/bin/perl
open(STDOUT,">/dev/tty");
select( (select(STDOUT), $| = 1)[0]);
print "read-only-1 STARTING\n";
while (<STDIN>) {
    tr/a-z/A-Z/;
    print;
}
print "read-only-1 DONE\n";
exit(0);

Again, at the unix level, do chmod +x read-only-1 to make the script executable.

(Remember that in this example we are sending the output to the unix /dev/tty device, hence it will work as shown only when running Muq from the unix commandline, not when telnetted into Muq.)

Now, at the Muq prompt do:

root:
makeSocket --> s
root:
makeMessageStream --> m
root:
m --> s$S.standardInput
root:
[ :socket s :commandline "|read-only-1" | ]rootPopenSocket
root:
read-only-1 STARTING

We now have the message stream m leading to our readOnly job read-only-1 via the socket s, and thus may feed test line-by-line to read-only-1 by stuffing it into m:

"testing 1...\n" m writeStream
root: 
TESTING 1...
"testing 2...\n" m writeStream
root:
TESTING 2...

As usual, you may close down the subprocess by doing

[ :socket s | ]closeSocket
read-only-1 DONE
root:


Go to the first, previous, next, last section, table of contents.