I am making a vnc client in vc++ and need to make it for TRLE encoding scheme. I am using tight vnc or real vnc as my server which are capable to send the data in TRLE (encoding value = 15). As I am new to RFB and VNC I am not sure now how do i read the data i am getting from the server ( i am aware that server sends it in message type 0 with x,y,w,h and encoding_type) and decode the data. Are there any examples present which i can use to understand the implementation of RFB and decoding techniques ? I found mostly ZRLE, Copyrect or Raw encoding examples on github and those were not clear enough on explanations.
RFB / VNC client in c++ (TRLE encoding)
4.2k Views Asked by aero.vish30 AtThere are 2 best solutions below

If you (re)implementing the wheel as academic exercise, you should go over the RFB protocol specification to understand the protocol and the encoding/decoding techniques.
If your intention is to simply have remote desktop viewer (possibly embedded within your application) there are simpler ways than to re-implement the protocol. Assuming you running Windows, you could simply launch the viewer as external process, grab its main window handle HWND and make it a child window of your own application using SetParent. Most viewers accept command line args that will allow you pass in the server / port to connect to.
There are a number of implementations already out there available (as viewers or static/dynamic link libraries) under many liberal licenses which should be suitable. Some of them are available in source form and it is possible they may have some comments in the code that describe the decoding part
A few I could find:
- TightVNC
- UltraVNC
- Not C++, but still useful VNCSharp
- TigerVNC
- libVNCServer/libVNCClient
Bit of googling led me to this.
The Server only sends you the data in encodings that you (the client) tell the Server you can receive. Since TRLE (15) is not well documented, you can drop it from your SetEncodings message and instead use of the other protocols that are better documented.
The best (living) documentation for the RFB protocol is here:
https://github.com/rfbproto/rfbproto
This is currently (Sept 2017) missing any TRLE documentation, such as this patch from 2009 https://www.mail-archive.com/[email protected]/msg00235.html
The SetEncoding message from the client to the server is a list of protocols the client understands, in order of preferred selection. RAW data is always possible, but will use the most data.
From experience, the easiest one to implement with the best bang-for-the-buck compression would be ZRLE (16) with raw rectangles, which is supported by most all servers, or the similar ZLIB (6).
It would be very weird if the server you are connecting to only supports TRLE and nothing else, but in that case you can still request "just RAW" data.