"IPC Inter-process communication two" pipeline pipe

Source: Internet
Author: User

IPC Inter-process communication+ Piping Pipe       IPC(inter-process communication. interprocess communication).

Pipelines are used to share data between processes, in fact the quality is shared memory. One of the IPC is often used.

The

pipeline can be used not only for native interprocess communication, but also for inter-network interprocess communication. Like socket communication. The same package of pipelines is implemented in the bottom network of the computer, providing a good API interface.                 1. Piping (pipe) :
        Pipelines are classified as anonymous pipes and named pipes.

Named pipes can be used for arbitrary interprocess communication. Supports cross-network communication, and communication is bidirectional. Be able to receive and send data at random intervals.

Named pipes are the focus of learning.

the named pipe communication process is divided into the service side and the client, and the server creates the pipe,client after the pipe is connected by the pipeline name. Both parties can send and receive data through the pipe.        2. Mail slot naming :on-machine format: \\ServerName\Pipe\namesuch as: \\.\pipe\my_pipe
3. Basic API Functions : To create a named pipe:HANDLECreateNamedPipe(
LPCTSTR lpname,Pointer to pipe name
DWORD Dwopenmode,Pipe Open Mode
DWORD Dwpipemode,Piping mode
DWORD nmaxinstances,Maximum number of instances
DWORD Noutbuffersize,Output Cache Size
DWORD Ninbuffersize,Input cache Size
DWORD Ndefaulttimeout,Timeout settings
lpsecurity_attributes lpsecurityattributesSecurity attribute pointer
);
This function is used to create a named pipe on the server side. Wait for client connection: BOOL connectnamedpipe(
HANDLE hnamedpipe, //pipe handle
lpoverlapped lpoverlapped //set to NULL
);
        This function is used by the server to wait for the client to connect to the pipeline.

to check Named pipes:         bool   waitnamedpipe (
                      lpctstr   lpnamedpipename,  //pipe name
                      dword     ntimeout                  //timeout
          This function is used by the client to check for the presence of piping pipe.

To open a named pipe:BOOL CreateFile(LPCTSTR lpFileName,
DWORD dwDesiredAccess,
DWORD dwShareMode,
Lpsecurity_attributes lpSecurityAttributes,
DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile
);first parameter: pipe name pointer. second parameter: access mode. third parameter: Shared mode. Fourth parameter: security attribute pointer.

Fifth parameter: Create an option. sixth number of parameters: file properties. Seventh parameter: used to copy a file handle. This function is used to open a pipe. and returns a pipe handle. Read pipeline:       & nbsp       bool  readfile                      handle    hfile,
                    LPVOID     lpbuffer ,
                    DWORD    nnumberofbytestoread,
&nb Sp                   LPDOWRD    lpnumberofbytesread,
                    lpoverlapped   lpoverlapped
first parameter: a pipe handle. second parameter: Cache address.

third parameter: the length of a message. Fourth parameter: the length of the actual read.

fifth number of parameters: generally set to null. This function is used to read the data in the pipeline. Write Pipeline:BOOL WriteFile(
HANDLE hfile,
Lpcvoid lpbuffer,
DWORD Nnumberofbytestowrite,
Lpdword Lpnumberofbyteswritten,
lpoverlapped lpoverlapped);
first parameter: a pipe handle.

Second parameter: A data buffer pointer. Third parameter : number of bytes written. Fourth parameter: Returns the actual number of bytes written. Fifth parameter: struct pointer. Null is generally placed.

This function is used by the client to write data to the pipeline.
4. Kind : The service-side program is executed in VC6.0 first. The client program is executing.
     Execution Effect:
Server program:client program:



"IPC Inter-process communication two" pipeline pipe

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.