Script TheSky  Version 1.32
Running a JavaScript Over a Network Socket

All the scriptable objects documented under 'Script TheSky' web site may also be called by an external program over a network TCP/IP socket.

The working sample application tcpscriptclient demonstrates this capability and is included in the download referenced at the bottom of every page of the 'Script TheSky' web site.

Running a script over a network socket is very similar to running a script from within TheSky under Tools, Run Java Script. When starting out, always test your scripts under Tools, Run JavaScript first, before attempting to run them over the network.

A java script run over a network socket must begin with a special key. Here is a java script, including the special key, sutiable for being run over a socket, that retreives the build number of TheSky:

    \* Java Script *\
    var Out;
    Out="TheSky Build=" +

Without the speical key, the script will do nothing when sent to TheSky over a socket.

For longer scripts that contain a lot of characters, to avoid being chopped up when sent over the network, scripts may optionally contain special socket start/end of packet keys.

Below is the same sample java script illustrating the socket start and end packet keys:

    \* Java Script *\
    \* Socket Start Packet *\
    var Out;
    Out="TheSky Build=" +
    \* Socket End Packet *\

TheSky will read the data between the socket start/end keys as a unit or timeout if no socket end of packet occurs. The maximum size of a script that can be run over a socket is (somewhat arbitrarily) set to 4096 bytes. If your script is bigger than this, try to break up the work into smaller pieces and or remove unnecessary comments.

Again, please refer to the tcpscriptclient application for a working example of running a java script over a network socket.

The output of a java script run over the network is entirely up to the one writing the script making this archtitecture very flexible to an almost endless number of needs.

Note if you are using netcat to send Java Scripts to TheSky, we have data showing the version of netcat that comes with (newer) Macs can prematurely close the socket connection while TheSky is in the midst of writing its response, the resulting symptom appears as blocked socket. The GNU version of netcat doesn't behave this way but are still waiting further testing.

Under Tools, Preferences, Advanced, there is an option "TCP responses close socket" that might help synchronize communication between external clients and TheSky in heavy traffic and or slow networks when there are occational, unexplained communication issues.
Turning this option on requires a new socket connection for each java script transaction.

The above socket start/end packet keys do nothing unless TheSky build 8291 or later is running (see Application::build).

ScriptTheSkyX Examples
(C) Software Bisque, Inc. All rights reserved.