HTML and CSS Reference
In-Depth Information
Listing 6-6. The versionHandler() Function
var versionHandler = function($this, stream) {
if (stream.length < 12) {
return false;
}
var version = new Uint8Array(stream.consume(12));
// Echo back version.
sendBytes($this, version.buffer)
// Set next handler.
$this.readHandler = numSecurityTypesHandler;
return true;
}
Enabling the Client to Accept Framebuffer Updates
Once you've connected the client to the server, the client must send a message requesting
framebuffer updates. Doing so will enable the client to receive the data from the
RFB server.
The RFB protocol defines different types of framebuffer updates. Each type is
indicated with a numerical code in the protocol message. In this example, we will only
use two basic encoding types: Raw and CopyRect. Raw, as you might guess, represents
pixel data as a raw, uncompressed bitmap. CopyRect is an instruction from the server to
copy a portion of the current bitmap elsewhere on the screen. Since many user interfaces
contain large solid color regions, this can be a very efficient way to update a client screen.
When no more rectangles remain in the stream, the client can request another
update. This implementation, as shown in Listing 6-7, is a compromise between polling for
and streaming the data in order to throttle server-sent updates without being too chatty.
Listing 6-7. Framebuffer Requests
var doUpdateRequest = function doUpdateRequest($this, incremental) {
var request = new CompositeStream();
request.appendBytes(3); // type (u8 3)
request.appendBytes(1); // incremental
request.appendBytes(0,0,0,0); // top left corner: x (u16 0) y (u16 0)
request.appendUint16($this.width); // width (u16 800)
request.appendUint16($this.height); // height (u16 600)
sendBytes($this, request.consume(request.length));
}
 
Search WWH ::




Custom Search