[prev] [up] [next]

Remote Scripting Service

Overview

The remote scripting service allows for ST/X itself or a standalone application written in ST/X to be remote controlled. It consists of a server (on the Smalltalk side), similar to the rdoit service, which awaits requests on a TCP connection. These requests consist of expressions in JavaScript syntax. The incoming expressions are evaluated, and the results are sent back to sender. All communication is done as ascii-text lines, where expressions are terminated with a semicolon. Therefore, any simple telnet-like communication tool can be used to interact with this service.
The possibilities and use are very similar to the rdoit service's; however, JavaScript syntax is used.

With the scripting service, you can:

Directives

The scripting service recognizes a number of directives. These are lines beginning with the escape character ~ (tilde) followed by the command character and optional arguments.

To get a list of supported directives, send a line beginning in "~?".

Language Changes

By default, expressions are interpreted in JavaScript syntax. This can be changed with the "~l" directive to one of the supported languages. For example, "~l smalltalk" switches to Smalltalk language. In Smalltalk language mode, expressions for evaluation are separated by a chunk-separator "!". However, the bang-character (!) must not be duplicated within a chunk.

Security Considerations

The script service enables full control over the system - not only the application itself, but also the underlying operating system. Therefore, access must be limited to trusted hosts. If required, the scripting service should be subclassed to filter incoming requests and restrict access. Alternatively, an authentication scheme could be added in such a subclass. Currently neither of these is provided out of the box.

Examples

Start Smalltalk with a "--scripting" argument, passing the port-number on which the scripting service should await incoming requests:
    stx --scripting 8008
By default, the script port only accepts connections from the local host. Using the "--allowHost" option, more hosts can be gained access to the scripting port:
    stx --scripting 8008 --allowHost myHostName

To start ST/X without IDE, you can use:

    ./stx --load "stx:goodies/simpleServices" -E "STXScriptingServer startAt:8008"
(the load argument is needed because the "stx:goodies/simpleServices"-package is not present in the minimalistic scripting environment)

Alternatively, start a scripting service from your Smalltalk program (or in a workspace or a startup script) by evaluating:

    STXScriptingServer startAt:8008
or via the Launcher's settings dialog.

Then, on any allowed host, start a session via telnet:

    telnet localhost 8008
you will a prompt similar to:
    Welcome to ST/X (Type ~? for help)
    > println("Hello world");
    Hello world
    > WorkspaceApplication.open();
    >
    ...
    >~.

    Lost Connection.
The scripting server supports session variables:
    > var app;
    > app = new WorkspaceApplication;
    > app.open();
    ...
    > app.paste("100 factorial");
    > app.selectAll();
    > app.printIt();
    ...
    > app.close();
    >~.

    Lost Connection.
and function definitions:
    > function foo(a) {
    >    println("hello "+a);
    > };
    ...
    > foo("smalltalk");
Language change:
    > WorkspaceApplication.open();
    ...
    >~l
      supported languages:
	JavaScript
	Smalltalk
    >
    ...
    >~l smalltalk
    > WorkspaceApplication open
    > !
    ...

No Warranty

This goody is provided AS-IS without any warranty whatsoever.

Origin/Authors


Author: Claus Gittinger


Copyright © 2009 eXept Software AG

<info@exept.de>

Doc $Revision: 1.11 $