桌面共享简介
桌面共享的为将一台计算机的桌面以某种协议进行编码,通过网络传输到另外一台计算机并进行重现。 主要应用在以下场景:- 以共享端为主的桌面共享、远程演示、课程教学;
- 以观看端为主的远程控制、远程协助、专家诊断;主要涉及安全领域,为桌面共享的最初应用;
目前主流的两种桌面共享的协议分别为RFB和RDP两种,其中RFB协议的实现主要为VNC系列,包含Real Vnc, Tight Vnc, UltraVnc, Chicken Vnc, FlashVNC,衍生出来的应用包含Proxy,Record, Repea,Nat2Nat, Mulitple Pointer,RFB协议具有很好的通用性,对观看端的要求非常低;RDP的实现主要包含Netmeeting,WIndows 远程桌面连接,Linux下面也有相应的观看端,但是没有共享端的实现。
VNC和RDP的对比;http://en.wikipedia.org/wiki/Comparison_of_remote_desktop_software
桌面共享的原理
核心为更新,利用不断的更新,从而还原出共享端屏幕;
1、观看端初始画面为空;
2、共享端截取屏幕,基于空画面,计算第一次更新,发送更新,并保留这一屏幕
3、观看端拿到第一更新,并显示为完整画面;
4、共享端截取屏幕,基于上次保留的屏幕,计算更新,发送更新,保留本次屏幕;
5、3和4不断循环,直至一方退出;
其中第2步的发送更新为桌面共享的核心,共享端会根据观看端的设定的编码格式和参数对更新进行编码,当前常见的编码格式包含如下几种:
本文将侧重RFB协议的介绍,然后再介绍RDP和RFB的对比,从而得出关于RDP的优缺点和应用模式。
RFB协议
RFB协议的特点是截取屏幕现实的图像,在共享端计算更新,利用网络发送更新给观看端,观看端只要求能够解码图片就可以显示。VNC的观看端只要求能够解码图像就可以还原出共享端的屏幕,所以观看端可以部署在和共享端完全不同的平台上,对硬件要求也非常的低,从而取得非常广泛的应用,成为目前桌面共享的主流协议。其传输图像保证观看端的低要求,但是也导致其传输的数据量比较大,对网络要求比较苛刻,对条件不好的网络的适应性比较差。同时,如果传输图像以外的内容,需要单独扩展RFB协议,造成目前很多版本的VNC实现的文件传输等功能,都不具有通用性,而且对音视频等实时内容无法对待。
RDP协议
介绍RDP协议的特点,实现和局限性;RDP协议借助更底层的技术,获取图像显示的API操作的参数,并在远程进行调用,从而还原出共享端的屏幕。由于其传输的是API及其参数,从而减少了数据量,相对于VNC,更适应条件不好的网络,但是其对观看端的硬件、操作系统要求比较苛刻。
桌面共享的选型
Raw
The raw encoding simply sends width*height pixel values. All clients are required to support this encoding type. Raw is also the fastest when the server and viewer are on the same machine, as the connection speed is essentially infinite and raw encoding minimizes processing time.
CopyRect
The Copy Rectangle encoding is efficient when something is being moved; the only data sent is the location of a rectangle from which data should be copied to the current location. Copyrect could also be used to efficiently transmit a repeated pattern.
RRE
The Rise-and-Run-length-Encoding is basically a 2D version of run-length encoding (RLE). In this encoding, a sequence of identical pixels are compressed to a single value and repeat count. In VNC, this is implemented with a background color, and then specifications of an arbitrary number of sub rectangles and color for each. This is an efficient encoding for large blocks of constant color.
CoRRE
This is a minor variation on RRE, using a maximum of 255x255 pixel rectangles. This allows for single-byte values to be used, reducing packet size. This is in general more efficient, because the savings from sending 1-byte values generally outweighs the losses from the (relatively rare) cases where very large regions are painted the same color.
Hextile
Here, rectangles are split up in to 16x16 tiles, which are sent in a predetermined order. The data within the tiles is sent either raw or as a variant on RRE. Hextile encoding is usually the best choice for using in high-speed network environments (e.g. Ethernet local-area networks).
Zlib
Zlib is a very simple encoding that uses zlib library to compress raw pixel data. This encoding achieves good compression, but consumes a lot of CPU time. Support for this encoding is provided for compatibility with VNC servers that might not understand Tight encoding which is more efficient than Zlib in nearly all real-life situations.
Tight
Like Zlib encoding, Tight encoding uses zlib library to compress the pixel data, but it pre-processes data to maximize compression ratios, and to minimize CPU usage on compression. Also, JPEG compression may be used to encode color-rich screen areas (see the description of -quality and -nojpeg options above). Tight encoding is usually the best choice for low-bandwidth network environments (e.g. slow modem connections).
Ultra
Experimental, Ultra encoding provides real time performance over a LAN by utilizing LZO compression. LZO is a data compression scheme which is suitable for data de-/compression in real-time. This means it favors speed over compression ratio.
其中Zlib、Tight为在互联网上广泛使用的协议。Tight协议的性能分析,可以参见http://www.tightvnc.com/archive/compare.html
共享端和观看端之间通产协商的参数包含如下几个:
1、颜色深度;
2、字节序:高位序和低位序
3、编码类型
一个VNC的应用流程如下:
1、服务器建立监听;
2、客户端和服务器建立连接;
3、交换协议版本;
4、认证;
5、两者交换参数和协议;
6、客户端设定参数和编码类型;
7、发送更新;
8、请求更新
参考资料:
http://en.wikipedia.org/wiki/Comparison_of_remote_desktop_software
http://en.wikipedia.org/wiki/Remote_Desktop_Services
http://en.wikipedia.org/wiki/RFB
http://en.wikipedia.org/wiki/Remote_Desktop_Protocol
http://people.gnome.org/~markmc/remote-desktop.html
http://msdn.microsoft.com/en-us/library/aa383015(VS.85).aspx