资源描述
2008 International Conference on Advanced Computer Theory and Engineering2008年高级计算机理论与控制工程国际会议An Effective Remote Control System Based On TCP/IP一种基于TCP / IP协议的有效远程控制系统Xueyu GengSchool of Civil Engineering 土木工程学院Qingdao Technological University 青岛理工大学Qingdao, 266033, China 中国青岛 26603gengxy gengxyShunyao Wu, Jinlong Wang, and Peng LiSchool of Computer Engineering 计算机工程学院Qingdao Technological University 青岛理工大学Qingdao, 266033, China 中国青岛 266033wangjinlong wangjinlongWith the network technology development, remote technology is gradually occupying the technology mainstream. It has become more and more popular in the home officeand distance education. The rapid development provides a broad world to the remote control software. Pcanywhere,damewhere, QQ Remote Assistance, and other remote control software have emerged. In remote control, improving efficiency and ensuring accuracy of the transmission are paramount to evaluate the success of a remote control software.This paper has developed a remote control system,and focuses on intercepting the control and the images, and TCP-stick packages. Solving these problems well is useful to improve the efficiency of the system and ease the pressureon network. Finally, through analysis and experiments, methods are proved to be effective.随着网络技术的发展,远程技术逐渐占据了技术的主流。对在家里办公和远程教育的人来说,它已经变得越来越受欢迎。它的快速发展为远程控制软件提供了广阔的天地。PcAnywhere, damewhere, QQ远程协助及其他远程控制软件已经出现,在远程控制领域,提高效率和确保准确的传输对评价一个远程控制软件的成功与否是极为重要的。本文描述了一种远程控制系统,并侧重于拦截控制、图像及TCP粘包。有效的解决这些问题,有利于提高系统的效率和缓解网络的压力。最后,通过分析和试验,方法被证明是有效的。1. Introduction1. 引言The rapid development of network technology, home office and distance education provides a broad world to the remote control software. As early as 1998, IDC expected the remote control software market would be the third fastest growing area in the consumer market which was supported by the software technology 1.随着网络技术的飞速发展,家庭办公和远程教育为远程控制软件提供了广阔的天地。早在1998年,IDC就预测远程控制软件的市场将是第三个由软件技术支持的消费市场里增长最快的领域。Remote control 1, 2, 3, 4 is a technology that administrators connect the target computer through the network by remote dialing or the way that both dial into Internet, then manage and maintain the remote computers by local host 1. The remote control software is based on the Client/Server model oriented towards connection agreement(TCP/IP). It includes a server program installed on the client, and a client program on the host. The general operating principle of remote control is shown in Figure 1.远程控制是一种管理员通过远程拨号上网或双方拨号接入Internet的方式连接目标计算机,然后通过本地主机管理和维护远程计算机的技术。远程控制软件是基于客户机/服务器模式面向连接协议(TCP / IP)。它包括安装在客户端上的服务器程序和在主机上的客户端程序。远程控制的基本工作原理见图1。Figure 1. One-to-one network topology remote control.图1 一对一远程控制网络拓扑图First of all, the client should set two kinds of authorities of passwords, and tell the IP address and password to the host.After building the connection, the host should set the image quality and FPS (frames per second). Then, the client captures the screen, compresses the images and sends the images to the host. After receiving the screen images, the host can watch the screen of the client. Finally, the host can control the client. When the host operates on the graphical interface, the mouse action and the keyboard input should be packaged to the client. The client operates the information,and sends the screen images to the host, and so on.首先,客户应设置两种类型的密码权限,告诉主机IP地址和密码。建立连接后,主机应设置图像质量和FPS(帧每秒),然后,客户端捕获屏幕,压缩图像并将图像传送到主机。收到屏幕图像后,主机可以查看客户端的屏幕。最后,主机可以控制客户端。当主机在图形界面上进行操作,鼠标的操作和键盘的输入被打包到客户端。客户端运行这些信息,并将屏幕图像等发送到主机。According to the basic process of the remote control as shown in Figure 1, the paper developed a remote control software, focused on intercepting the control and the images, and TCP-stick packages. Solving these problems well is useful to improve the efficiency of the system and ease the pressure on network. Finally, with analysis and experiments, methods are proved to be effective.依据如图1所示的远程控制的基本过程,本论文描述了一个远程控制软件,侧重于拦截控制、图像及TCP粘包。有效的解决这些问题,有利于提高系统的效率和缓解网络的压力。最后,通过分析和试验,方法被证明是有效的。The rest of the paper is organized as follows. Section 2 introduces the overview framework of remote control system and the function of each subsystem. The detailedmethod to solve the control interception will be introduced in Section 3, and the method to solve the image capture and the image display is described in Section 4, and the solution of the TCP-stick packages in Section 5. The experimentalanalysis is described in Section 6. The paper is concluded in the last section.本文的其余部分具体如下。第2部分介绍远程控制系统的框架概述和各子系统的功能。第3部分介绍控制拦截的详细的解决方法,第4部分介绍图像采集和图像显示的解决方法,第5部分介绍TCP粘包解决方案,第6部分中介绍实验分析,论文最后部分得出结论。2. Overview Framework2. 框架概述Figure 2. The relations among the six subsystems.图2 六个子系统之间的关系The paper divided remote control system into six subsystems, authority subsystem, communications subsystem,captured images subsystem, images display subsystem, intercepted control subsystem, and simulation control subsystem.Figure 2 is a brief diagram of the relations among the six subsystems.本文将远程控制系统分为六个子系统,权限子系统、通信子系统、捕捉图像子系统、图像显示子系统、截获控制子系统及仿真控制子系统。图2是六个子系统关系的简要图。The functions of the six subsystems are as follows:六个子系统的功能如下:1. Authority subsystem manages the user authority. The client can set two kinds of passwords, one only to watch and the other to control. Two kinds of passwords are stored in the document after encrypted. The host inputs the respective password to get the appropriate authority.1. 权限子系统管理用户的权限。客户端可以设置两种密码权限,一种只浏览,另一种可控制。两种类型的密码都存储在加密后的文件里。主机输入相应的密码以获得相应的权限。2. Communications subsystem is primarily responsible for communications between the host and the client.The subsystem is divided into host and client module. Host module is mainly responsible for transmitting the image information to the client, while client module is mainly responsible for transmitting the mouse action and the keyboard input to the host.2. 通信子系统主要负责主机和客户端的沟通。该子系统分为主机和客户端模块。主机模块主要负责向客户端传输图像信息,而客户端模块主要负责向主机传递鼠标操作和键盘输入命令。3. Intercepted control subsystem intercepts the mouse action and the keyboard of the host, and gives these information to host module of communications subsystemafter packaging them. Then, host module transmit these information to the client.3. 截获控制子系统截取主机的鼠标操作和键盘输入,打包后向通信子系统的主机模块给出了这些信息,然后,主机模块发送这些信息给客户端。4. Simulation control subsystem obtains the mouse action and the keyboard input from client module of communications subsystem.4. 仿真控制子系统获得来自通信子系统客户端模块的鼠标操作和键盘输入。5. Captured images subsystem calls the function to capture screen in the client, and stores the images formatted in BMP in memory, and converts BMP images toJPEG images, in order to facilitate the rapid transmission on the network.5. 捕捉图像子系统在客户端调用函数捕获屏幕,将图像以BMP格式存储在内存中,并且为了便于在网络上迅速传播,将BMP图像转换为JPEG图像。6. Images display subsystem reverts the data received from communications subsystem to JPEG images, and converts them to BMP images, and displays these images on the screen in the host.6. 图像显示子系统将来自通信子系统的数据还原为JPEG格式图像,并将其转换为BMP格式图像,在主机屏幕上显示这些图像。3. Intercepted Control Subsystem3. 截获控制子系统Generally speaking, intercepted control subsystem is mainly responsible for the interception of the mouse action and keyboard input. The intercepted accuracy will directly affect the accuracy of simulation control subsystem. For example, users move the mouse to the location of a folders over the graphical interface, while the coordinates of the mouse is (0,0). Then double click operates it, but coordinatesof the mouse which is got by intercepted control subsystem is (1,0). This may result in errors that the client can not correctly implement, and is unable to open the selectedfolder. In addition, when the subsystem intercepts information, it should be payed a lot attentions on the validity.We can avoid intercepting unnecessary information toimprove the efficiency. When authentication successes and user operate the host, intercepted control subsystem should take different measures by user authority. If the authority is to control, it will intercept the mouse action and keyboard input; if not, it will not. Once intercepted control subsystem intercept the mouse action and keyboard input, the problem of the interception field should be put first. When user operatesthe host, it will never be always intercepted. Some other things may be solved. If intercepted control subsystem do not fix the interception field, some useless information will be intercepted. This will result in some very difficult problems that simulation control subsystem is difficult to design and implement. In addition, it will reduce the efficiency.一般来说,截获控制子系统主要负责鼠标操作和键盘输入的拦截。被拦截的精度将直接影响仿真控制子系统的精度。例如,用户移动鼠标到一个文件夹的图形界面位置,鼠标的坐标是(0,0),然后双击运行它,但截取图像子系统上的鼠标的坐标变为(1,0)。这可能因为错误导致客户端不能正确执行,并且无法打开选定的文件夹。此外,当子系统截取信息时,应当多关注有效性。我们可以避免不必要的信息拦截进而提高效率。当身份验证成功,用户操作主机时,截获控制子系统应当通过用户权限采取不同的措施应对。如果权限是控制,它会拦截鼠标操作和键盘输入,反之,则不会。一旦截获控制子系统拦截鼠标操作和键盘输入,截取领域出现的问题应放在一位。当用户操作主机,它将永远不会被截获。一些其他的事情可能得到解决。如果拦截控制子系统不能控制拦截领域,一些无用的信息将被拦截。这将导致出现一些非常棘手的问题,仿真控制子系统将很难设计和实施。此外,它会降低工作效率。In order to solve the problem about the interception field, the paper tried several measures:为了解决拦截领域出现的问题,本文尝试了几种措施:1. With hook to achieve the interception of mouse actionand keyboard input. The basis for determining the interception field, two points must be met at the same time.1.将鼠标操作和键盘输入挂钩实现拦截。确定拦截领域的基础是,以下两点必须同时满足。 Intercepting only if the system window is active; If the system window is active, the position of the mouse should be in the working area.仅在系统的窗口处于活动状态时拦截如果系统窗口处于活动状态,鼠标的位置应在工作区表1 3种方法的比较复杂性困难性效率方法1困难更难低方法2容易更难低方法3容易-高2. With the functions such as PreTranslateMessag, WindowsProc and so on to intercept. Although implementing these functions is easier than hook, the interceptedinformation is almost all the windows messages. Thus choosing this method should do the same work as the above one.2. 如拦截PreTranslateMessag,WindowsProc的功能等。虽然实施这些功能比挂钩容易,被拦截的几乎所有都是Windows信息。因此,选择此方法应做上述同样的工作之一。3. Overloading the mouse message function of CView class; while the keyboard input is also intercepted by the function PreTranslateMessag. The mouse messagefunctions are the member functions of CView class.Only if the mouse move in the working area, interception is doing. In this way, there is no need to determinewhether the mouse is in the working area. The method saves time and space, and improves efficiency.3.重载CView类的鼠标消息功能,而键盘输入也是由函数PreTranslateMessag截获。鼠标消息函数是CView类的成员函数。只有当鼠标在工作区移动,拦截才是有效的。用这种方法,没有必要再确定鼠标是否在工作区。该方法节省了时间和空间,提高了效率。Table 1 analyzes and compares three methods from the complexity, the difficulty to intercept field and efficiency.As a result, this paper selected the third method. Themethod is easy to implement, does not determine the interception field and has a higher efficiency.表1分析和比较三种方法的复杂性,拦截领域的难易度和效率。因此,本文选择了第三种方法。该方法容易实现,不决定拦截领域,具有更高的效率。4. Capture and Display Images4. 捕捉和显示图像In the development of captured images subsystem and images display subsystem, we should put the use of bandwidth first. As remote control system is mainly used forLAN transmission1. The transmission speed in local area network is usually 10 Mbps to 100Mbps. Therefore, the transmission bandwidth should reach 10Mbps. The clientshould set the image quality and the transmission speed on the basis of network bandwidth. The captured images are stored in BMP format. Each 1024*768 BMP with 24-bit color graphics needs more than 2MB space. Even if the transmission fps is 1 fps, the bandwidth needs reach at least 16 Mbps, far more than 10 Mbps. So the images must be compressed before transmission.随着捕获图像子系统和图像显示子系统的发展,我们应该把它首先应用于宽带。远程控制系统主要用于局域网的传输1。在局域网的传输速度一般为10 Mbps到100Mbps的。因此,要达到10Mbps的传输带宽。客户应在网络宽带的基础上设置图像质量和传输速度。截获的图像存储为BMP格式。每个24彩色的1024*768的BMP图像需要超过2MB的空间。即使是一帧帧传输,需要的带宽至少达到16 Mbps,远远超过10 Mbps。因此,图像必须压缩后传输。After capturing the images, the system will store them in a certain format, such as BMP, JPEG. The two methods are different. Although using BMP is easy, data traffic need a harsh bandwidth, and scalability is not strong. It is not conductive to operate in the future. However, JPEG compression is convenient, with large compression ratio and small distortion. Therefore, the paper made use of CXImage class library to compress JPEG.拍摄的照片后,系统会存储在一个特定格式,如BMP,JPEG格式。这两种格式是不同的。虽然BMP使用容易,但需要一个较大的数据流量的带宽,可扩展性不强。这在未来不利于经营。然而,JPEG压缩方便,拥有大压缩比和失真小的特点。因此,本文使用CxImage类库压缩JPEG图像。After captured images subsystem does the screen-shot, it will pass the image formatted in memory block to the Cx-Image category formatted. CxImage class can immediately convert the memory blocks to JPEG image. With CxImage class, system will do a JPEG compression operation. The process sets the compression quality, from 0 to 100 (the numerical representation for image quality). After compression,communications subsystem will send them to the host.通过截获图像子系统截图后,它会通过在内存块格式化为CxImage的图像类型。CxImage可以立即将内存块转换为JPEG图像。系统用CxImage做一个JPEG压缩操作。该程序压缩质量从0到100(图像质量数值表示)。压缩后,通信子系统将它们发送到主机。Secondly, we should solve how to make users convenient to set image quality, transmission speed and so on. If we compress the images in a fixed proportion following the same pattern, and do not consider the state of users network,it may happen that users whos bandwidth is low feel the screen is not coherent, while users whos bandwidth is high feel image quality is not good. Therefore, in the actualuse process, users should be able to adjust the image compression level according to the current state of the network.其次,我们要解决如何使用户方便地设置图像质量、传输速度等问题。如果我们压缩在一个固定比例的图像千篇一律,不考虑用户的网络状态,有可能发生有些用户带宽感觉画面不连贯,有些用户感觉宽带感觉图像质量不好。因此,在实际使用过程中,用户应该能够根据网络当前状态调整图像的压缩级别。Thirdly, we should consider the transmission number per second. On the basis of different purposes, different realtime levels is need. So, it need users to set the imagefps. When a user requests high realtime level, the image fps should be improved. Then, the change of the image will be faster, and the user needs will be met.第三,我们在不同用途不同实时级别的基础上应该考虑每秒传输次数是很必要的。因此,用户需要设置图像帧。当用户要求高的水平,图像的FPS应该加以改进。这样,图像的变化会更快,用户需求将得到满足。In the middle level compression, a 1024*768 JPEG image whos plans are 32 color need only 80 KB. In the 4/s fps, occupied bandwidth is about 2.5 Mbps. It is good to adapt to the local area network bandwidth requirements, and image quality and fluency can meet users requirements.中间级别压缩的时候,计划是32色彩的1024 * 768的JPEG图像只需要80 KB。4/s帧时,占用带宽大约是2.5 Mbps。这能很好的适应本地区域网络带宽的要求,满足用户图像质量和流畅度的要求。5. The Solution of TCP-stick Packages5.TCP粘包的解决方案Communications subsystem is responsible for communication between the client and the host. Firstly, the subsystem is necessary to ensure the accuracy of the data transmission, avoiding data loss. However, if you use the default TCP protocol, the interception information can not be completely simulated in the host. The reason is that the interception information is all relatively short. It is prone to stick the TCP packages, and ultimately, it will result in the illusion that lost data packages.通讯子系统负责客户端和主机的通信。首先,该子系统是要保证数据传输的准确性,避免数据丢失。但是,如果您使用默认的TCP协议,截取信息不能完全在主机上模拟。其原因是,拦截的信息都相对较短。它很容易粘贴TCP程序包,并最终会因为错觉失去数据包。With the method2, towards TCP-stick packages caused by sender, we can avoid this problem through program setting, and make use of the operation push supplied by TCP, which can immediately transmit the data. Once TCP receives the operation, it will immediately send out data in this paragraph, rather than waiting until the buffer is full. Towards the TCP-stick packages caused by receiver, we can receive data in time, through optimizing the program design, simplifying the workload of the receiving process, improving the priority of the receiving process, and so on. Furthermore, the data packages can be set to field structure. It is controlled by sender, and multiply received in human control. Finally, we can merge them. The method can completelyavoid TCP-stick packages in the case of paying a little efficiency .使用方法2,针对发件人引起TCP粘包,我们可以通过程序设置避免这个问题,并使用有TCP提供的可以立即传输数据的操作推进。一旦TCP收到的操作,它会立即发出在本段数据,而不是等到缓冲区满。对接收器引起的TCP粘包,我们可以及时收到数据,通过优化方案设计,简化了接收过程的工作量,提高接收进程优先级,等等。此外,数据包可以被设置为外地结构。它是由发件人和认为控制的加快接收器控制。最后,我们可以将它们合并。这种方法可以完全避免TCP粘包效率低的情况。The paper selected the third method. The method designed the communication protocol, and packed all the data. Before sending data, data head ExMSG in a fixed-sized will be sent. The data head includes the type and size of the followingdata. This will receive the following data in fixed size, and the problem of TCP-stick packages will be naturally solved.本文选择了第三种方法。该方法设计的通信协议,包装了所有数据。发送数据前,数据头ExMSG将固定大小发送。数据头包括以下数据类型和大小。这将获得适合大小的数据,TCP粘包的问题将自然解决。struct ExMSG3MSGTYPE msgtype;/head message commandint size;/the size of the command or data ;enum MSGTYPE4COMMAND, /commandKEYBOARD, /keyboard inputMOUSE, /mouse actionPASSWORD, /the connection passwordCONFIRM, /the return value after connection is bulitIMAGE, /imageIMAGEQUALITY, /image qualityIMAGEFPS, /image fpsDEFINITION / resolution;ExMSG3结构MSGTYPE msgtype / /头信息命令int size,/ /命令或数据大小;例如 MSGTYPE4COMMAND,/ /命令KEYBOARD, / /键盘输入MOUSE,/ /鼠标动作PASSWORD,/ /连接密码CONFIRM,/ /连接后的返回值是储存卡IMAGE,/ /图像IMAGEQUALITY,/ /图像质量IMAGEFPS,/ /图像帧DEFINITION / /分辨率;6. Experimental Result and Analysis6. 实验结果及分析6.1. Comparisons of the Image Capacity6.1 图像存储容量的比较This section will compare BMP and JPEG from image quality and capacity. For the convenient of testing, the client program should be changed. The captured images not only are converted data flow to send to communications subsystem, but also are stored on the hard drive formatted in BMP and JPEG. Then, we can compare their image quality and image capacity.本部分将从质量和容量上比较BMP和JPEG图像。为了方便测试,客户端程序应有所改变。捕捉的图像不仅是转换后的数据流发送到通信子系统,而且是以BMP和JPEG格式存储在硬盘驱动器。这样,我们可以比较其图像质量和图像的容量。The comparison between BMP and JPEG captured the same screen is shown in Table 2, the image quality is that the compressed image quality selected on the program menu Quality, including HIGH, MIDDLE, LOW.在同一个屏幕捕捉BMP和JPEG格式之间的比较,如表2所示,图像质量是在程序菜单中选择的压缩图像的质量,包括高,中,低。As shown in Table 2, the difference before compression and after is very large, and the compression ratio reaches to 39:1. It greatly reduces the requirements for bandwidth. Except for the image capacity, the image quality is a very important problem. After testing, the image quality of the two images in Table 2 is similar.如表2所示,压缩前后差异非常大,压缩比达到39:1。它大大降低了对带宽的要求。除图像存储容量外,图像质量是一个非常重要的问题。经过测试,在表2的两幅图的图像质量是相似的。6.2. Comparison of Image Quality and Capacity6.2 图像质量和存储容量的比较After BMP image is converted to JPEG in the client, in order to adapt to different control to the image quality requirements, it is necessary to compress images. The compression ratio is determined by three kinds image quality: HIGH, MIDDLE and LOW.BMP格式图像转换后在客户端显示为JPEG格式,为了适应对图像质量的不同控制要求,有必要压缩图像。三种图像质量决定了不同的压缩比:高,中,低。When the requirement for the image quality is not high, setting low image quality is ok; when the requirement is higher, we can set MIDDLE or HIGH to obtain better quality image. Table 3 lists three compression ratio.当图像的质量要求不高,设置较低的图像质量也可;当要求更高,我们可以设置中等或高等的以获得更好质量的图像。表3列出了三种压缩比。6.3. An ExampleFigure 3 is a graphical interface that the host with the control authority is controlling the client.6.3一个例子图3是有控制权限的主机控制客户端图形界面7. ConclusionsThe paper mainly designed remote control system, and focused on intercepting the control and the images, and TCP-stick packages. Solving these problems well is useful to improve the efficiency of the system. The system can be improved in some other respects, including changing the topology from one-to-one to one-to-many, and dealing the images with secondary compression. This can improve efficiency,and reduce network bandwidth, and so on.7.结论
展开阅读全文