UNIX domain socket IPC-blueliuyun column-blog channel-csdn. net

Source: Internet
Author: User
Tags unix domain socket

UNIX domain socket IPC-blueliuyun column-blog channel-csdn. net

4. UNIX domain socket IPC

The socket API was originally designed for network communication, but later an IPC Mechanism was developed on the socket framework, namely the Unix domain socket. Although the network socket can also be used for inter-process communication between the same host (through the loopback address 127.0.0.1), the Unix domain socket is more efficient for IPC:It does not need to pass through the network protocol stack, and does not need to package or unpack, calculate the checksum, maintain the serial number and response,Only copy application layer data from one process to another. This is because,The IPC Mechanism is essentially reliable communication, and the network protocol is designed for unreliable communication.. UNIX domain socket also provides two API interfaces, namely stream-oriented and data packet-oriented, similar to TCP and UDP. However, message-oriented Unix domain socket is reliable, and messages are neither lost nor disordered.

The Unix domain socket is full-duplex and has rich API interface semantics. Compared with other IPC Mechanisms, it has become the most widely used IPC mechanism, such as the X Window server and GUI.ProgramCommunication is through Unix domain socket.

The process of using Unix domain socket is very similar to that of network socket. You must first call socket () to create a socket file descriptor,Address Family is specified as af_unix, Type can be sock_dgram or sock_stream,The Protocol parameter is still set to 0.You can.

Programming of Unix domain socket and network socketThe most obvious difference is that the address format is different, represented by the addr_un struct.The Network Programming socket address is the IP address and port number, while the Unix domain socket address is the path of a socket-type file in the file system. This socket file is created by the BIND () call, if the file already exists when BIND () is called, The BIND () error is returned.

The following program binds a Unix domain socket to an address.

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.