Remote screen monitoring system based on IOCP

Abstract: Using the completion port ( IOCP ) model provided by Windows, the remote screen monitoring server in C / S mode can simultaneously monitor the screen of a large number of concurrent clients. You can decide whether to start remote control according to your needs. Use IOCP to schedule and manage multiple threads to efficiently use system resources. And gives the network design and implementation process of the entire system.

Keywords: IOCP; multithreading; remote screen monitoring

Microsoft introduced IOCP (I / O CompleTIon Port, I / O completion port) in Windows NT 3.5. This model is widely used on large-scale network servers. The remote screen monitoring server can effectively control multiple Monitor on the client screen.

1 The overall structure of the remote screen monitoring system

In the Windows system, the C / S mode is generally designed for large-scale server applications, and information transmission is realized by establishing a network connection between the client and the server. For the server, multiple client screens may need to be monitored at the same time. The general structure of the remote screen monitoring system is shown in Figure 1.

The screen image captured by the monitored client is compressed and transmitted to the server in real time. The server opens a window and displays the received client screen image data in the window. If the client needs to be controlled, the server The terminal sends the mouse and keyboard message captured in the window to the client. After receiving the message, the client simulates a mouse and keyboard click event to realize remote control. Using the IOCP mechanism, only a few threads are needed to provide services to multiple clients at the same time, and the efficiency is much higher than other network models.

2 Basic principles of IOCP mechanism

IOCP is the best I / O model. It is a mechanism for applications to use thread pools to handle asynchronous I / O requests. When processing multiple concurrent asynchronous I / O requests, the previous model was to create a thread to answer the request when receiving the request. In this way, there are many threads running in the system in parallel. These threads are all runnable, and the Windows kernel spends a lot of time in thread context switching, and not much time is spent running threads. In addition, the overhead of creating new threads is relatively large, which causes inefficiency.

The goal of IOCP is to achieve an efficient server program, which overcomes the deficiencies of the general concurrency model. The method is to create a certain number of service threads when initializing the completion port. After the system completes the I / O operation, it sends an I / O compleTIon packet to the server completion port. At this time, the threads in the thread pool queue up on the completion port to wait for the completion of the I / O operation. If no I / O compleTIon packet is received on the completion port, these threads are asleep. Otherwise, these threads are awakened in a LIFO fashion and complete subsequent data processing operations.

3 Server design

The core function of the remote screen monitoring server is to display the received screen image of the client to a server-side window, through which the server remotely controls the client. In order to improve the reliability of the system, the network protocol uses the connection-oriented TCP protocol. The congestion avoidance, timeout and error retransmission mechanism in the TCP protocol can be used to ensure the reliability of data transmission.

3.1 Implementation of server listening socket

When establishing the IOCP model on the server side, you first need to establish a listening socket. For the listening socket, you do not associate it with the completion port, but call WSAEventSelect to register the FD_ACCEPT network event for the listening socket. The function declaration is as follows:

Then create a listener thread, in this thread you can call WSAWaitForMulTIpleEvents in a loop to wait for the event object to be triggered. After the function returns correctly, continue to call the WSAEnumNetworkEvents function to enumerate the events that occurred on the socket. If it is an FD_ACCEPT event, accept the connection and associate the newly created socket with the created completion port. Call WSARecv on the socket to post the request to receive data.

3.2 Implementation of IOCP model

To establish the IOCP model, you need to create a completion port object when the server starts the listening thread, and call CreateIoCompletionPort to achieve it, and then call the GetSystemlnfo function to obtain the number of CPUs, create a certain number of service threads based on the number of CPUs, and wait on this port The notification of the completion event, in general, the number of service threads is about twice the number of CPUs.

Electric Iron Burner

Portable Electric Burner,Electric Cookers,Counter Top Cooking Tools,Electric Iron Burner

Shaoxing Haoda Electrical Appliance Co.,Ltd , https://www.zjhaoda.com

This entry was posted in on