Content-type: text/html Manpage of TclRFB

TclRFB

Section: Tcl Raster Framebuffer Library (n)
Updated: APRIL 2003
Index Return to Main Contents
 

NAME

TclRFB - Tcl-based Raster Framebuffer (RFB) library  

SYNOPSIS

package require tclRFB ?0.5?

rfb::CreateClientSocket host port optlist

rfb::SendFramebufferUpdateRequest sockN inc

rfb::SendKeyEvent sockN downflag keysym

rfb::SendPointerEvent sockN button pressed

rfb::SendClientCutText sockN cutbuffer

rfb::CreateServerSocket port optlist

rfb::SendBell sockN

rfb::SendServerCutText sockN text

rfb::SendFramebufferUpdate sockN encodeList

rfb::ConnectionShutdown sockN

rfb::EncryptPasswdToFile password filename




 

DESCRIPTION

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.

TclRFB requires Tcl 8.4 or later to run. It does not rely on any given visualization library. Any visualization library 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  

RFB Client Commands

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 the server port number, and optlist is a list of option-value pairs. Note that TclRFB 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 primarily describe the client's pixel characteristics and the routines 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.

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 routines passed to rfb::CreateClientSocket in the option list. The client routines take the pixel data provided through the RFB encodings and uses the client visualization library to display the pixels.

The option list is a proper Tcl list containing TclRFB property option-value pairs as sublists. The following option/value pairs MUST be defined in the option list passed:

clientVersionMajor number
Major number of the client's RFB protocol version (3 for protocol version 3.3).
clientVersionMinor number
Minor number of the client's RFB protocol version (3 for protocol version 3.3).
clientBPP 8|16|32
Number of bits per pixel (8, 16, or 32) of the client.
clientDepth number
Number of useful bits in a pixel for the client. This value must be less than or equal to the value given to clientBPP.
clientBE 1|0
Big-endianess of the client data.
clientTC 1|0
True-color flag for the client.
clientRmax number
Maximum red value ((2^bits)-1) for the client.
clientGmax number
Maximum green value ((2^bits)-1) for the client.
clientBmax number
Maximum blue value ((2^bits)-1) for the client.
clientRshift number
Number of bit shifts of red data to align to the least-significant bit for the client.
clientGshift number
Number of bit shifts of green data to align to the least-significant bit for the client.
clientBshift number
Number of bit shifts of blue data to align to the least-significant bit for the client.
clientShared 1|0
Allow server connection to be shared with other viewers.
passwd password
Unencrypted 8-byte password.
passfile filename
File containing the encrypted 8-byte password.
encode_list list
Ordered list of encoding types. The RFB encoding types currently supported are 0, 1, 2, 4, and 5.
delay msec
Delay for emit of next frame buffer update request in milliseconds.
bell procname
Tcl procedure to ring the console bell. The procedure procname will be called from the client state machine as follows:

procname

The procedure has no input parameters.

clientsetup procname
Tcl procedure to set up the client display once an RFB protocol connection has been established with a server. The procedure procname will be called from the client state machine as follows:

procname sock

Where sock is the client's socket handle.

colormappings procname
Tcl procedure to process color mapping data. The procedure procname will be called from the client state machine as follows:

procname sock

Where sock is the client's socket handle.

servercuttext procname
Tcl procedure to process cut text sent from the server. The procedure procname will be called from the client state machine as follows:

procname text

Where text is the cut text sent from the server.

rawenc procname
Tcl procedure to render raw encoded pixel data. The procedure procname will be called from the client state machine as follows:

procname sock x y w h

Where sock is the client's socket handle, x and y are the horizontal and vertical coordinates of the upper-lefthand corner of the pixel region, and w and h are the width and height of the pixel region.

copyrect procname
Tcl procedure to copy pixel data from one area of the client framebuffer to another. The procedure procname will be called from the client state machine as follows:

procname srcX srcY dstX dstY w h

Where srcX and srcY are the horizontal and vertical coordinates of the upper-lefthand corner of the source pixel region, dstX and dstY are the horizontal and vertical coordinates of the upper-lefthand corner of the destination pixel region, and w and h are the width and height of the pixel region.

colorrect procname
Tcl procedure to render a colored rectangle. The procedure procname will be called from the client state machine as follows:

procname pixel x y w h

Where pixel is the pixel value received from the server, x and y are the horizontal and vertical coordinates of the upper-lefthand corner of the pixel region, and w and h are the width and height of the pixel region.

screenupdate procname
Tcl procedure to invoke a screen update. The procedure procname will be called from the client state machine as follows:

procname

The procedure has no input parameters.

Application-specific array variables can be created via additional option-value pairs. The following option names are reserved for internal use by the client and should not be used:

buttonmask clientBytes clientPixel

bgPixel fgPixel serverBE

serverTC serverBPP serverDepth

serverBmax serverGmax serverRmax

serverBshift serverGshift serverRshift

serverBytes serverPixel state                     

serverVersionMajor serverVersionMinor

Several library produres provide client-to-server protocol messages:

rfb::SendClientPixelFormat sock
rfb::SendClientPixelFormat sends the SetPixelFormat message (message type 0) to the RFB server connection referenced by the socket handle sock. The pixel format data sent is acquired from the internal client variables set through the options list submitted with the call to rfb::CreateClientSocket that created the client connection..
rfb::SendEncodings sock
rfb::SendEncodings sends the SetEncodings message (message type 2) to the RFB server connection referenced by the socket handle sock. The encoding data sent is acquired from the internal client variable set through the options list submitted with the call to rfb::CreateClientSocket that created the client connection.
rfb::SendFramebufferUpdateRequest sock inc
rfb::SendFramebufferUpdateRequest sends the FramebufferUpdateRequest message (message type 3) to the RFB server connection referenced by the socket handle sock. The argument inc specifies whether the update should be an incremetal update (1) or a full (0) update.
rfb::SendKeyEvent sock downflag keysym
rfb::SendKeyEvent sends the KeyEvent message (message type 4) to the RFB server connection referenced by the socket handle sock. The argument downflag specifies whether a key press (1) or a key release (0) has occurred. The argument keysym specifies the keysym value sent.
rfb::SendPointerEvent sock button pressed
rfb::SendPointerEvent sends the PointerEvent message (message type 5) to the RFB server connection referenced by the socket handle sock. The argument button specifies the button number (1 - 8). The argument pressed specifies whether the button was pressed (1) or released (0).
rfb::SendClientCutText sock cutbuffer
rfb::SendClientCutText sends the ClientCutText message (message type 6) to the RFB server connection referenced by the socket handle sock. The argument cutbuffer specifies the text sent from the client cutbuffer to the RFB server.
 

RFB Server

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

rfb::CreateServerSocket port optlist

Where port the server port number and optlist is a list of option-value pairs. Note that TclRFB can use any port including those traditionally used by VNC servers.

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.

Routines provided by TclRFB take the pixel data supplied by the server and converts 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.

The option list is a proper Tcl list containg TclRFB property option-value pairs as sublists. The following option/value pairs MUST be defined in the option list passed:

serverVersionMajor number
Major number of the servers's RFB protocol version (3 for protocol version 3.3).
serverVersionMinor number
Minor number of the servers's RFB protocol version (3 for protocol version 3.3).
scheme 1|2
Authentication scheme used by the server. The allowable schemes are no authentication (1) and VNC authentication (2).
width number
Width of the server frame buffer in pixels.
height number
Height of the server frame buffer in pixels.
serverBPP 8|16|32
Number of bits per pixel (8, 16, or 32) of the server.
serverDepth number
Number of useful bits in a pixel for the server. This value must be less than or equal to the value given to serverBPP.
serverBE 1|0
Big-endianess of the server data.
serverTC 1|0
True-color flag for the server.
serverRmax number
Maximum red value ((2^bits)-1) for the server.
serverGmax number
Maximum green value ((2^bits)-1) for the server.
serverBmax number
Maximum blue value ((2^bits)-1) for the server.
serverRshift number
Number of bit shifts of red data to align to the least-significant bit for the server.
serverGshift number
Number of bit shifts of green data to align to the least-significant bit for the server.
serverBshift number
Number of bit shifts of blue data to align to the least-significant bit for the server.
serverShared always|never|client
Server connection always to be shared with other viewers. Allowable values are "always", "never", or "client" determined.
name string
Descriptive name of the server.
passwd password
Unencrypted 8-byte password.
passfile filename
File containing the encrypted 8-byte password.
updaterequest procname
Tcl procedure to process an update request from the client The procedure procname will be called from the server state machine as follows:

procname sock inc x y w h

Where sock is the socket handle for the server connection instance, inc specifies whether the update should be an incremetal update (1) or a full (0) update, x and y are the horizontal and vertical coordinates of the upper-lefthand corner of the pixel region, and w and h are the width and height of the pixel region.

keyevent procname
Tcl procedure to process a key event from the client The procedure procname will be called from the server state machine as follows:

procname sock downflag keysym

Where sock is the socket handle for the server connection instance, downflag specifies whether a key press (1) or a key release (0) has occurred, and keysym specifies the keysym value sent.

pointerevent procname
Tcl procedure to process a pointer event from the client The procedure procname will be called from the server state machine as follows:

procname sock buttonmask x y

Where sock is the socket handle for the server connection instance, buttonmask specifies the buttons (1-8) that are depressed (1) or released (0), and x and y are the coordinates of the mouse pointer.

servercuttext procname
Tcl procedure to process cut text from the client. The procedure procname will be called from the server state machine as follows:

procname sock text

Where sock is the socket handle for the server connection instance, and text specifies the text sent from the client cutbuffer to the RFB server.

Application-specific array variables can be created via additional option-value pairs. The following option names are reserved for internal use by the server and should not be used:

clientBE clientTC clientBPP

clientBytes clientPixel clientDepth

clientBmax clientGmax clientRmax

clientBshift clientGshift clientRshift

clientShared serverBytes serverPixel

clientVersionMajor clientVersionMinor

port state

Several library produres provide server-to-client protocol messages:

rfb::SendColourMapEntries sock first colorList
rfb::SendColourMapEntries sends the SetColourMapEntries message (message type 1) to the RFB client connection referenced by the socket handle sock. The argument first specifies the index of the first color in the map. The argument colorList is a list of red-green-blue color triplets for each color in the color map.
rfb::SendBell sock
rfb::SendBell sends the Bell message (message type 2) to the RFB client connection referenced by the socket handle sock.
rfb::SendServerCutText sock text
rfb::SendServerCutText sends the ServerCutText message (message type 3) to the RFB client connection referenced by the socket handle sock. The argument text specifies the text sent from the server cutbuffer to the RFB client.
rfb::SendFramebufferUpdate sock encodeList
rfb::SendFramebufferUpdate sends the FramebufferUpdate message (message type 0) to the RFB client connection referenced by the socket handle sock. The argument encodeList is a proper Tcl list containg data specifying RFB encoded rectangles. The encodeList has a general format of


   {rectangle1 rectangle2 ... rectangleN}

where each rectangle is a list in the form


   {type x y w h data1 data2}

where type is the number of the RFB encoding type, x and y are the horizontal and vertical coordinates of the upper-lefthand corner of the rectangle, w and h are the width and height of the rectangle, and data1 and data2 are data elements specific to the RFB encoding type.

The specific formats for the different RFB encodings are as follows

Raw encoding (type 0)


   {0 x y w h datastring {}}

where datastring is a binary string of pixels, w times h times pixel bytes in length, formated to the client color format. The pixel ordering is left-to-right, top-to-bottom like scanlines.

CopyRect encoding (type 1)


   {1 x y w h srcX srcY}

where srcX and srcY are the coordinates of the upper-lefthand corner of the source rectangle.

RRE encoding (type 2)


   {2 x y w h bgPixel rectList}

where bgPixel is the background pixel color formated to the client color format and rectList is a proper Tcl list of subrectangles


   {subrectangle1 subrectangle2 ... subrectangleN}

where each subrectangle is a proper Tcl list


   {xs ys ws hs fgPixel}

where xs and ys are the horizontal and vertical coordinates of the upper-lefthand corner of the subrectangle with respect to the RRE rectangle's coordinates, ws and hs are the width and height of the subrectangle, and fgPixel is the foreground pixel color formated to the client color format.

CoRRE encoding (type 4)


   {2 x y w h bgPixel rectList}

where bgPixel is the background pixel color formated to the client color format and rectList is a proper Tcl list of subrectangles


   {subrectangle1 subrectangle2 ... subrectangleN}

where each subrectangle is a proper Tcl list


   {xs ys ws hs fgPixel}

where xs and ys are the horizontal and vertical coordinates of the upper-lefthand corner of the subrectangle with respect to the RRE rectangle's coordinates, ws and hs are the width and height of the subrectangle, and fgPixel is the foreground pixel color formated to the client color format. Note that ws and hs can be no larger than 255.

Hextile encoding (type 5)


   {hextile1 hextile2 ... hextile256}

where each hextile is a proper Tcl list consisting of an eight-bit binary mask value and additional data depending upon the binary mask value.

Hextile of a solid rectangle of last background color


   {0}

Hextile of raw pixels


   {1 datastring}

where datastring is a binary string of pixels, formated to the client color format. The pixel ordering is left-to-right, top-to-bottom like scanlines.

Set a new background color for subsequent hextiles


   {2 bgPixel}

where bgPixel is the new background color specified in the client color format.

Set a new foreground color for subsequent hextiles


   {4 fgPixel}

where fgPixel is the new foreground color specified in the client color format.

Hextile of solid rectangle of new background color and a new foreground color is set


   {6 bgPixel fgPixel}

where bgPixel is the new background color specified in the client color format and fgPixel is the new foreground color specified in the client color format.

Hextile of solid rectangle of last background color and subrectangles of last foreground color


   {8 srects subrectangle1 subrectangle2 ... subrectangleN}

where srects is the number of subrectangles. Following are "N" Tcl lists that represent the number of subrectangles specified by srects. The format of each subrectangle is


   {xs ys ws hs}

where xs and ys are the horizontal and vertical coordinates of the upper-lefthand corner of the subrectangle with respect to the particular hextile, and ws and hs are the width and height of the subrectangle, which cannot be greater than 16 pixels. The color of each subrectangle is that of the foreground color in the last hextile.

Hextile of a solid rectangle of new background color and subrectangles of last foreground color


   {10 bgPixel srects subrectangle1 subrectangle2 ... subrectangleN}

where bgPixel is the new background color formated to the client color format, srects is the number of subrectangles, and "N" Tcl lists as specified above for hextile mask 8.

Hextile of a solid rectangle of last background color and subrectangles of new foreground color


   {12 fgPixel srects subrectangle1 subrectangle2 ... subrectangleN}

where fgPixel is the new foreground color formated to the client color format, srects is the number of subrectangles, and "N" Tcl lists as specified above for hextile mask 8.

Hextile of a solid rectangle of new background color and subrectangles of new foreground color


   {14 bgPixel fgPixel srects subrectangle1 subrectangle2 ... subrectangleN}

where bgPixel is the new background color formated to the client color format, fgPixel is the new foreground color specified in the client color format, srects is the number of subrectangles, and "N" Tcl lists as specified above for hextile mask 8.

Hextile of a solid rectangle of last background color and subrectangles with individual foreground colors


   {24 srects subrectangle1 subrectangle2 ... subrectangleN}

where srects is the number of subrectangles. Following are "N" Tcl lists that represent the number of subrectangles specified by srects. The format of each subrectangle is


   {xs ys ws hs fgPixel}

where xs and ys are the horizontal and vertical coordinates of the upper-lefthand corner of the subrectangle with respect to the particular hextile, ws and hs are the width and height of the subrectangle, which cannot be greater than 16 pixels, and fpPixel is the foreground color of the subrectangle specified in the client color format.

Hextile of solid rectangle of new background color and subrectangles with individual foreground colors


   {26 bgPixel srects subrectangle1 subrectangle2 ... subrectangleN}

where bgPixel is the new background color specified in the client color format, srects is the number of subrectangles, and "N" Tcl lists as specified above for hextile mask 24.

Several library produres provide for general support:

rfb::ConnectionShutdown sock
rfb::ConnectionShutdown halts the state machine and closes the socket connection referenced by the socket handle sock.
rfb::EncryptPasswdToFile password filename
rfb::EncryptPasswdToFile encrypts the eight-byte string password and stores the encrypted password into the file specified by filename.
 

AUTHOR

Mac A. Cody <maccody at attbi dot com>

 

SEE ALSO

binary(n), socket(n)

 

KEYWORDS

RFB, VNC, Tcl, package
 

Index

NAME
SYNOPSIS
DESCRIPTION
RFB Client Commands
RFB Server
AUTHOR
SEE ALSO
KEYWORDS

This document was created by man2html, using the manual pages.
Time: 03:31:42 GMT, May 06, 2003