Introduction and Comparison of four inter-process communication modes

Source: Internet
Author: User
Createpipe (& m_hread, & m_hwrite, & SA, 0) creates an anonymous Pipeline
CreateProcess (".. // child // debug // child.exe", null, true,
0, null, null, & Sui, & PI) Pass the anonymous pipeline read and write handle of the parent process to Sui. hstdinput = m_hread through the startupinfo structure Sui;
Sui. hstdoutput = m_hwrite;
Similarly, read and write data from the pipeline through readfile and writefile

Named Pipe
Server:
Hpipe = createnamedpipe ("//. // pipe // mypipe ",
Pipe_access_duplex | file_flag_overlapped,
0, 1, 0, null); // create a named pipe
Handle hevent;
Hevent = createevent (null, true, false, null );
Overlapped ovlap;
Zeromemory (& ovlap, sizeof (overlapped ));
Ovlap. hevent = hevent;
Connectnamedpipe (hpipe, & ovlap) // wait for the client to connect
Waitforsingleobject (hevent, infinite) // wait for the event to occur
Then read data from the pipeline through readfile and writefile

Client:
Waitnamedpipe ("//. // pipe // mypipe", nmpwait_wait_forever) // connect to the MPs queue
Hpipe = createfile ("//. // pipe // mypipe", generic_read | generic_write,
0, null, open_existing, file_attribute_normal, null); // open an existing pipeline
Then read data from the pipeline through readfile and writefile

The server side of the oil tank can only receive data, and the client can only send data. Because it is based on the broadcast communication system, the oil tank can be used, encode multiple servers and one client to implement a one-to-many network system.
Server:
Handle hmailslot = createmailslot ("//. // Mailslot // mymailslot", 0,
Mailslot_wait_forever, null); // create a tank
Readfile (hmailslot, Buf, 100, & dwread, null) // read data
Client:
Hmailslot = createfile ("//. // Mailslot // mymailslot", generic_write, file_assist_read,
Null, open_existing, file_attribute_normal, null); // open the Oil Tank
Writefile (hmailslot, Buf, strlen (BUF) + 1, & dwwrite, null) // write data

The clipboard and anonymous pipeline can only communicate between two processes on the same machine, but cannot communicate across networks. The named pipeline and the oil tank can both, you can also implement one-to-many communication for the oil tank, while the named pipe can only be a point-to-point communication. However, the number of messages sent in the tank is less than 424 bytes.

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.