Remote screen display and control technology based on socket communication

Source: Internet
Author: User
Tags bind set socket socket client port number

Remote control technology has wide application foreground in the maintenance, monitoring and fault diagnosis of remote equipment (software), and mostly uses client/server mode. The structure includes multiple computers that are connected to the network, those that handle applications, and those that request another computer service are client computers (local machines), and the computer that responds to requests and processes requests is called the server (the target machine).

The principle of remote control [1] is: When a user connects to a network, the client sends authentication information and requests to connect to a remote host, the remote host server program authenticates the client, and if it is validated, establishes a connection with the customer and sends the user the authentication pass and established connection information. At this point, the user can send instructions to the remote host via the client program, the server-side program executes these instructions and passes the keyboard, mouse, and screen refreshes to the client, which, by processing the display of information such as the host screen, makes the user act as if it were on a remote host. This approach is referred to as remote service based remote control (remotely controlled over remote services).

To sum up, to achieve the client's remote control of the server, we need to solve 3 problems such as dual socket network communication, remote interception screen display and screen data transmission control.

1 dual-machine socket network communication [2]

Initialize the service socket: Initialize the socket before calling it, that is, load the corresponding version of the DLL, and by calling the WSAStartup function, fill in the lpwsadata structure with the relevant information of the successful socket library version;

Wsadata Lpwsadata;

WSAStartup (Makeword (1,1), &lpwsadata);

Create a service-side socket: After initialization, the socket function is called to create a socket, return the socket handle, always identify the socket in the subsequent communication, and return Invalid_socket if the call fails;

SOCKET Sktconnect=socket (af_inet,sock_stream,0);

Binding service-side address: After a socket is created for a particular protocol, the BIND function is used to bind the socket to a native address of type sockaddr, which is used to indicate the socket binding address, including the IP address and port number;

Bind (Sktconnect, (struct sockaddr FAR *) &sockaddrin,sizeof (Sockaddrin));

Service-Side Listening network: Socket use the Listen function to set the state bit, used to detect the incoming connection request, and then call the Accept function, ready to receive the client connection signal, no connection request, the service process is blocked;

Listen (sktconnect,1);

Sktclient=accept (sktconnect, struct sockaddr FAR *) &sockaddrin,& Sockaddrlen);

Initialize and create client Winsock: First use the AfxSocketInit function to determine whether the parameter lpwsadata is empty, to determine whether to call the WSAStartup function to populate the WSADATA structure, and then call the socket function to create the socket for the client , the SOCKADDR_IN structure is assigned to the client, and the address type and the port number are the same as the service end;

Socket option settings: Use the SetSockOpt function to set socket options, such as sending or receiving timeout settings, buffer capacity settings, using the Ioctlsocket function to set the socket I/O mode, etc.

int Ret=ioctlsocket (Sktclient,fionbio, unsigned long*) &ul);

The two sides establish a connection: the client invokes the Connect function to send a connection request to the server, and when the connection request arrives, the accept function of the blocked server generates a new byte stream socket, returns the client sockaddr_in structure variable, and connects with the client with the socket with the client address. , and then returns the receiving signal to the client;

Connect (sktclient, (const struct SOCKADDR *) &sockaddrin,sizeof (Sockaddrin));

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.