HTML and CSS Reference
In-Depth Information
setter methods on the ArrayBuffers with bytes representing 8, 16, and 32 bit integers.
Listing 6-3 shows the numerical functions in bytes.js .
Listing 6-3. Numerical functions in bytes.js
$prototype.appendBytes = function appendBytes() {
ba = new Uint8Array(arguments);
$prototype.appendUint16 = function appendUint16(n) {
var b = new ArrayBuffer(2);
var dv = new DataView(b);
dv.setUint16(0, n);
$prototype.appendUint32 = function appendUint32(n) {
var b = new ArrayBuffer(4);
var dv = new DataView(b);
dv.setUint32(0, n);
These functions make it easier to write arrays of bytes containing messages in the
syntax of the RFB protocol.
Setting Up the Connection
The RfbProtocolClient connect function sets the initial client state and creates an
empty stream, a WebSocket, and event handlers for that socket. This function also
sets the first readHandler to versionHandler , since the RFB protocol starts with an
exchange of version information between the server and client. Listing 6-4 shows the
RfbProtocolClient connect function we must set up to connect to our server. The
connect function also constructs an empty CompositeStream . That stream will contain
bytes representing partial RFB messages from the server.
Listing 6-4. RfbProtocolClient Connect Function
RfbProtocolClient = function() {};
$prototype = RfbProtocolClient.prototype;
$prototype.connect = function(url) {
this.socket = new WebSocket(url);
this.socket.binaryType = "arraybuffer"; = new CompositeStream();
bindSocketHandlers(this, this.socket);
Search WWH ::

Custom Search