24. Windows API inter-process communication and other inter-process communication modes

Source: Internet
Author: User

1. Dynamic Data Exchange (DDE) and Network Dynamic Data Exchange (ndde) [1, 2]

DDE may be the most powerful communication method between processes, and its implementation is also very complicated. The two ends of the communication are divided into the server and the client. Both ends must have a window.

The communication process of a DDE is roughly as follows:

The DDE session is initiated by the client and initialized first. The DDE client sends a wm_dde_initiate window message to the server. After receiving the message, the service window determines whether to respond to the message based on the conditions. If the server determines that a session can be established with the client, the message wm_dde_ack is returned. If the client successfully receives the wm_dde_ack window message sent by the server, the session is established and data is transmitted.

Data transmission can be divided into multiple methods. You can transmit only one data item, or create a permanent data link ).

If independent data items are transmitted, the unit of data transmission is data items. The client uses wm_dde_request and wm_dde_poke messages to receive and send data items to the server. The wm_dde_data message is used for data transmission.

The establishment of a permanent data connection is also initiated through the client. The client sends the wm_dde_advise message to the server. The server responds based on the situation and returns different wm_dde_ack messages based on whether the connection can be established. Terminate the data connection and use the message wm_dde_unadvise.

The client can also use wm_dde_execute to send commands to the server.

Terminate a dde session to use the wm_dde_terminate message.

Almost all the processes are requests initiated by the client, while the server responds. The server mostly sends a wm_dde_ack message.

DDE communication requires help from the atom table of the operating system to index data. The atom table has a dedicated API.

2. share data between processes through file mapping [3]

Shared Files are an efficient way of communication between processes. Because the memory is directly shared, the access speed is very fast. It also allows massive data transmission.

Compared with other inter-process communication modes, shared memory has fewer restrictions. For example, the mail slot limits the data size and data stream. The pipe can only use half-duplex communication, and the clipboard is easily affected by other processes.

Sharing data with file mapping also has disadvantages. The biggest drawback is the inability to implement real-time performance. After a process writes or reads data, the other process does not know whether the operations of the other process have been completed. Therefore, when real-time data transmission is required, file mapping is usually used in combination with other processes to transmit a large amount of data.

3. Windows Socket

Inter-process communication implemented using Windows Socket uses the principle of socket communication. In fact, any mechanism that allows network data communication between two hosts can be used for inter-process communication.

If both the socket server and the Socket Client are used on a host, the client specifies the IP address as the local machine when connecting to the server, communication between the socket server process and the Socket Client process on the same host can be realized.

Using socket for inter-process communication can realize real-time performance and transmit large data volumes, and the data transmission speed is also very fast. Therefore, it is widely used.

The principle andProgramThe implementation method is no different from the socket communication between different hosts.

Reference

[1] proficient in Windows API functions, interfaces, and programming instances

[2]Http://msdn.microsoft.com/en-us/library/ms648711%28VS.85%29.aspx

[3] http://www.cnblogs.com/mydomain/archive/2011/01/07/1929874.html

Related Article

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.