Saturday, June 11, 2011

Tcl and Remote Desktop

TclRFB 0.5

TclRFB is a pure-Tcl implementation of the Remote Framebuffer (RFB) protocol that is used in the Virtual Network Computing (VNC) remote desktop application. Currently, TclRFB supports version 3.3 of the RFB protocol. Both client and server functions are supported. Multiple client and/or server instances can exist within the same interpreter. Currently supported RFB encodings are Raw, CopyRect, RRE, CoRRE, and Hextile.
TclRFB requires Tcl 8.4 or later to run. It does not rely on any given widget library. Any widget library with bindings to Tcl can be used (e.g. Tk, gnocl (gTk), or the Tcl bindings to FLTK) or none at all. The authentication component of the protocol is fully supported when either the TclDES (Data Encryption Standard and Triple-DES) or TclDESjr (Data Encryption Standard only) extension is used with TclRFB. The TclDES and TclDESjr extensions can be obtained at http://tcldes.sourceforge.net/.
The TclRFB extension is implemented as the rfb namespace. Within this namespace, procedures and variables that support the protocol are isolated from the global namespace. Additional details of the RFB protocol can be found in "The RFB Protocol" by Richardson and Wood at http://www.realvnc.com/docs/rfbproto.pdf
The intent of TclRFB is to enable the creation of light-weight, scripted remote interfaces, much like Proxy Tk, used in TeamWave (for information, see http://www.usenix.org/events/tcl2k/full_papers/roseman/roseman_html/). The user interface can then be displayed through a VNC viewer, using either the standalone version (Unix, Windows, Macintosh, Palm, and other platforms), the Java-based version running in a web browser, or one based on TclRFB.

Installation

To install the TclRFB library, simply copy the directory tclRFB0.5 and its contents to a directory whose path is listed in the Tcl auto_path variable. Alternately, the path to the TclRFB library can be added to the auto_path variable.
Once the installation is done, the TclRFB library can be loaded into a Tcl interpreter using the package command:
package require tclRFB
This will create the rfb namespace.

RFB Clients

An RFB client is started by making a call to rfb::CreateClientSocket. This procedure is invoked as follows:
rfb::CreateClientSocket host port optlist
Where host is the hostname or IP address (dotted quad) of the computer running a server supporting the RFB protocol, port is the server port number, and optlist is a list of option-value pairs. Note that TclRFB clients can use any port including those traditionally used by VNC servers.
The list of option-value pairs describes the properties of the client. These properties are primarily the client's pixel characteristics and the procedures used to handle the RFB pixel encodings that support the client visualization. The client pixel characteristics are used to inform the server as to the pixel format best handled by the client. The server must transform its local pixel representation into that supported by the client. Additional details of the client options and procedures used to implement an RFB client are presented in the man page.
The call to rfb::CreateClientSocket creates an instance of an RFB client state machine. The state machine processes RFB protocol messages coming from the server. Pixel data received from the server is passed to the client visualization procedures whose names were passed in the option list to rfb::CreateClientSocket. The client procedures take the pixel data provided through the RFB encodings and uses the client visualization library to display the pixels.
An example RFB client, client.tcl, is provided to demonstrate how to use the TclRFB library's client procedures. It can be found in the examples subdirectory of the distribution. The client supports bgr233 truecolor pixel format and 24-bit truecolor (rgb888) pixel format. The user can select the hostname/IP and the port number or display number of the RFB server. The display number port assignment corresponds to that used with VNC, i.e. the port number is equal to the display number plus 5900. Sharing of the connection with other RFB clients can be enabled as well. A password or the path to a file containing an encrypted password can be specified. RFB pixel encoding preferences can also be selected.
The client has been tested against the Unix VNC server 3.3.3r2 and the TclRFB server, rfbcounter.tcl, mentioned below. Either TclDES or TclDESjr must be installed to support RFB authentication. The performance of the TclRFB client compares favorably to that of the Unix vncviewer. Noticeable rendering lags do occur when mouse cursor movements cause focus changes between windows and when large amounts of screen area are written. A screen shot of the client connected to a Unix vncserver is shown here. A screen shot of the client connected to the rfbcounter.tcl server is shown here.

RFB Servers

An RFB server is created by making a call to rfb::CreateServerSocket. This procedure is invoked as follows:

rfb::CreateServerSocket port optlist
Where port is the server port number and optlist is a list of option-value pairs. Note that TclRFB servers can use any port including those traditionally used by VNC servers. The socket that is created then waits for connections from RFB clients.
When a client connects to the server, a server connection instance is created via a call to rfb::AcceptServerSocket. The parameters passed to rfb::CreateServerSocket are applied to the server socket instance. An RFB server state machine is created to process the RFB protocol messages that come from the client.
Procedures provided by TclRFB take the pixel data supplied by the server and convert it to RFB protocol messages. It is the responsibility of the server to make sure the pixel data is in the format appropriate for the client prior to submitting it for encoding. Additional details of the server options and procedures used to implement and RFB are presented in the man page.
An example RFB server, rfbcounter.tcl is provided to demonstrate how to use the TclRFB library's server procedues. This server is inspired by the rfbcounter described at http://www.uk.research.att.com/vnc/rfbcounter.html. It can be found in the examples subdirectory of the distribution. The server supports either a six-digit counter or a 24-hour clock (when the -clock option is specified), which displays in HH:MM:SS format. The foreground and background colors can be also be specified. The display number port assignment corresponds to that used with VNC, i.e. the port number is equal to the display number plus 5900.
The only pixel format supported by the server is bgr233. The only RFB encoding protocol supported is RRE. Therefore, any RFB client that intends to connect to the server must support these formats.
The server has been tested against the Unix VNC viewer 3.3.3r2 and the TclRFB client, client.tcl, mentioned above. It has also been tested with multiple clients connecting to it simultaneously. Either TclDES or TclDESjr must be installed to support RFB authentication. A screen shot of a Unix vncviewer connected to the rfbcounter.tcl server is shown here.

Future goals

There are serveral areas in which TclRFB can be improved or experimented upon:
  • Speed up the pixel encoding and decoding operations.
  • Implement additional of RFB encodings (e.g. ZRLE).
  • Create a user guide.
  • Create more example applications. One currently in development is a TclRFB server that "screen scrapes" from and supplies events to a Tk user interface. It uses the Img extension to facilitate "scraping" the Tk widgets.
  • Use OpenSSL and the TLS extension to enclose the RFB protocol in a secure tunnel. I don't know if this will connect properly to traditional VNC secure tunneling techniques such as ssh/VNC, stunnel/VNC, or ZeBeDee/VNC.
  • Combine TclRFB with tclhttpd to allow serving of the Java VNC client to a browser. Alternately, the Java VNC client could be replaced with a TclRFB client that would run on the Tcl/Tk plugin.

Downloads

TclRFB 0.5 is available as either gzipped tar archive for GNU/Linux (and other Un*xes) or pkzip archive for Microsoft Windows. Both can be obtained at the TclRFB SourceForge Files page.
Earler versions of TclRFB can also be found at the TclRFB SourceForge Files page.

Feedback

Feedback and suggestions for new features for TclRFB are invited. Be aware that development is still ongoing. New versions of TclRFB will be made available as time allows. You can send your emails to maccody@home.com. Replace "home" with "attbi" for all you non-spammers!

Tcl and Android

Tcl and the Android Scripting Environment


 Android when running on a phone does not permit general installation of binaries. The only significant writable filesystem is the sdcard but that is mounted with a non-exec flag to prevent anything running from the card. This means you need to install applications using the system installer which has permission to create files and directories on the data filesystem. The Android Scripting Environment is a project which provides a java shim to get compiled scripting languages installed onto the phone from where they can run script files from the sdcard. It comes with Python, Lua and some others.


I have created a Tcl interpreter package for ASE and it is currently hosted at http://www.patthoyts.tk/tclkit/android-arm This is a modified version of the ASE project to add Tcl support. You need to install the APK file and then copy the three zip files to the root of your sdcard and have ASE install the Tcl8.6b2 interpreter. This includes support for using the JSON interface to the Android interface so the various examples posted for other languages are readily translated into Tcl. See the scripts package but a sample is:

package require android
  set android [android new]
  $android vibrate
  $android getInput "Hello!" "Type something in..."
  $android webSearch "android scripting with tcl"


In the longer term it is probably more sensible to use something with better Java integration. Either Hecl or Jacl would seem good candidates. Hecl is not-quite-tcl and Jacl needs some updating. When I tested a threaded build and tried to create a thread in Tcl the executable aborted so I suspect we cannot make use of tclblend which says it requires threads.

Note that Hecl already has support for Android (see above).


SL4A Supports Tcl

escargo 2010-08-20 - Quoting from this link ([5]):


"Scripting Layer for Android (SL4A, formerly known as Android Scripting Environment or ASE) brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreters directly on the Android device. These scripts have access to many of the APIs available to full-fledged Android applications, but with a greatly simplified interface that makes it easy to get things done. Scripts can be run interactively in a terminal, in the background, or via Locale. Python, Perl, JRuby, Lua, BeanShell, JavaScript, Tcl, and shell are currently supported, and we're planning to add more."



Sample Programs:


package require Tcl 
package require android 
set android [android new] 
 
puts "auto_path: $auto_path" 
 
$android vibrate 
 
#$android getRingerVolume 
#$android showContacts 
#$android getInput "title string" "Enter something" 
#$android scanBarcode 
#$android pickContact 
#$android webSearch "android scripting tclsh" 
 
#set time [clock format [clock seconds] -format "%I %M %p on %A, %B %e %Y."] 
#$android speak $time 
 
$android makeToast "You are using Tcl [info patchlevel] on Android!!" 
 
set pkgs [$android getRunningPackages] 
 
 
flush stdout 
after 1000 {set ::forever 1} ; vwait ::forever 

Tcl in NASA

fitsTcl: TCL interface to FITS Files


fitsTcl is an extension to the TCL language, providing simple access to astronomical data stored in FITS file format. fitsTcl implements a TCL interface to the CFITSIO library, developed by the HEASARC (High Energy Astrophysics Science Archive Research Center) at the NASA Goddard Space Flight Center. fitsTcl is primarily distributed as part of the fv FITS file editor. It is also available by itself below. The latest version is 2.3, released July, 2009. This is identical to the version in the most recent release of fv (version 5.3, released July, 2009).

XSPEC and tcl/tk

XSPEC uses the Tool Command Language (tcl) to process command input. Because tcl is a full scripting language, this interface allows users to write complex scripts with loops, branching, etc., which utilize XSPEC commands. In this section of the help file we describe how to use those features of tcl necessary to give the user similar functionality to that available in previous versions of XSPEC, and to give information on the details of our tcl implementation that may be useful to experienced tcl users. For a description of tcl, see, for example, "Practical Programming in Tcl and Tk", B. Welch, (1997, Prentice Hall).
Tk, tcl's companion graphical user interface (GUI) toolkit, is also loaded by XSPEC on startup. It is planned that future versions of XSPEC will provide an optional GUI side-by-side with the command line interface (CLI). Although XSPEC does not currently use tk, its presence allows users to write XSPEC scripts with graphical interfaces using Tk commands.

XImage and Tcl Scripting

Tcl Scripting

Tcl is a scripting language which provides new capabilities to the ximage command line beyond the program-specific commands, allowing for example if-branching and looping which was previously unavailable to ximage scripts.
This page is a primer for Tcl scripting in ximage and contains only basic Tcl commands. For a full reference of all Tcl commands, see the Tcl manual (Use command "puts $tcl_patchLevel" in ximage to determine version).

LHEATcl Plugin API

The LHEATcl Plugin is an enhanced version of the TCL Plugin version 2.0 source release. The version number of the current LHEATcl release is 2.0 despite the fact that it is the first official release in order to match the version number of the TCL plugin that it "descends" from. The LHEATcl Plugin adds the following extra features to the plugin:
  • The dash patch : This adds several missing things to the Tk canvas widget. These include dashed and stippled outlines, the "visitor" patch to allow easier extension of canvas capabilities, and postscript output for images. See the dash patch home page for details.
  • FitsTcl: This adds the ability to read and write FITS files. It is essentially a Tcl interface to cfitsio
  • POW: A scientific curve and image plotting and interface widget which uses the Tk canvas with several extensions to produced curve plots, images, contours, histograms, etc. Since y using the Tk canvas, user input can be done almost any way you wish.
  • The LHEA orbit library. This is currently under development and in release 2.0, only three functions are present which are built into the POW library, but in future releases, this will be a separate package adding spacecraft orbit calculation utility routines.
Follow the links above to get in depth information on any of the LHEATcl components. Documentation for the original Tcl plugin is here. What follows is a brief description of how the plugin works followed by some sample tclets.

Maki - XRS FOV and Multi-Mission Observing Windows


Maki is a tool designed to serve two purposes: investigating instrument Fields of View (FOV's), and viewing multi-mission observing windows.
Maki allows the user to plot a detector FOV onto a FITS image, further allowing the user to investigate different roll angles. This is useful, for example, for the case of an observation of an extended target which requires a specific roll angle. Maki allows the user to see when the target is observable for the given roll angle.
While previous versions of Maki allowed users to overlay FOV's directly via Skyview, the current version does not support this functionality. Further, at this time, Maki has only been built and tested on Linux and Solaris. We are working to port Maki to other platforms. If you do not have access to Linux or Solaris machines, please drop us a note.