Principle of Remote Computer Control
1. Method
L C/S Mode
The C/S mode is similar to PCANYWHERE. A Server and a client are required to be installed on different computing instances. The client computer controls the computer on which the server is located. Generally used in a LAN, the TCP protocol is used. If you use it on the internet, you may need a proxy server or a server, but it is greatly affected by the firewall.
L Web Mode
It is a B/S mode. It is actually a variant of the C/S mode, but the client is a browser. Therefore, the client does not need to install specific software, but the server still needs to install software. When any compute wants to access this server, it will go to the specified web page to get the specified connection. He needs at least one WEB server. In order to ensure communication security and cross-firewall and LAN communication, it is best to have another communication service.
2. Principles
The above two modes are similar in principle and require a network communication server and client, but the two modes may have different clients (one is the developed application, the other is the browser, which actually communicates through the plug-in on the browser), but the mechanism for sending data and obtaining control is the same.
Here, the server and client are used for explanation.
L server side
The server needs to run a software based on TCP/IP (usually TCP is relatively reliable) and listen on a port (a well-known port for the client ). It is a multi-threaded program. When listen sends a request to the client, a new thread is generated to process client requests.
Because it is a remote control program, the client's request is nothing more than viewing the screen, transferring files, operating the server program, etc. The following explanations:
View the screen: after the client is connected, the server sends the screen to the client, the processed image is sent (the format and compression algorithm of the image are very important here). However, an important issue is how to change the screen, if you keep sending messages, it is undoubtedly the most stupid way. There are many ways, one is to check the amount of changes in the image information, and the other is to refresh the hardware graphics card (this method has been implemented by Microsoft/WEBEX, etc, but this method is very helpful for performance ). The obtained image must be adjusted according to the client resolution.
Server Operation Program: when the client operates on the screen, it actually operates on the image to get its mouse event/keyboard event and coordinates, send the information to the server. The Server analyzes the obtained information, parses different system messages (WM _) based on different information, and restores the system messages through the mouse_event and key_event functions, to obtain the client operation.
Transfer File: knowing the above two processes, transferring a file is just a copy process.
L client
The client needs to know the server IP address and port (if it is on the WEB, the information is obtained from the WEB server, and port 80 is generally used), and then the client sends a connection request, if the server is online, it is connected.
After the connection, first obtain the server screen, which is actually an image file, and then display it on the client based on the client's resolution. There will be two situations in the future:
1. The Server actively sends the information (this happens only when someone is operating on the server). The client only needs to update the screen.
2. The Client sends the changed information. At this time, the screen does not need to be changed, but the updated content will be sent from the server.
When the Client runs the server computer, it first obtains the position on the current image, converts it to the coordinates on the server, records the mouse time and Keyboard Events, and sends them together to the server.
3. Implementation
The above is a basic process, and mainly on the window platform, the use of socket can implement the communication part. Of course, the specific implementation code still has some workload.