Inter-domain socket socketpair

" Inter-domain socket socketpair "

       Pipe is used to create a pipe, but a single pipe can only communicate in one direction, one end is used for reading, and the other end is used for writing. If you want to achieve two-way communication between processes, you must create a pair of pipes, and socketpair can be used to create two-way communication pipes. The specific implementation is as follows:

 

        

       " Domain " : indicates the protocol family, which can only be AF_LOCAL or AF_UNIX;

       " Type " : Indicates the type, which can be SOCK_STREAM or SOCK_DGRAM. The socket pair established with SOCK_STREAM is a pipe stream. The difference from the general pipe is that the channel established by the socket pair is bidirectional, that is, both ends can read and write. The parameter sv is used to save the established socket pair;

 

       " Protocol " : indicates the protocol, which can only be 0;

       " Sv[2] " : Receive an array of integers representing two sockets. Each file descriptor represents a socket and is not different from another.

       When the return value of the socketpair() function is 0, it means the call was successful, and when it is -1, it means an error occurred.

 

mysocketpair.c

        

        

 

       " Run Results " :

        

 

 

Guess you like

Origin blog.csdn.net/wxt_hillwill/article/details/73864383