Hands-On System Programming with Go
上QQ阅读APP看书,第一时间看更新

Sockets

Unix domain sockets are a bidirectional communication method between applications on the same machine. They are a logical endpoint that is handled by the kernel and manages the data exchange.

The nature of sockets permits using them as stream-oriented, or datagram-oriented. Stream-oriented protocols ensure that messages are delivered before moving to the next chunk of data in order to preserve message integrity. In contrast, message-oriented protocols ignore the data that is not received and keeps sending the following messages, making it a faster but less reliable protocol with very low latency.

The sockets are classified as follows:

  • SOCK_STREAM: Connection-oriented, ordered, and reliable transmission of a stream of data
  • SOCK_SEQPACKETConnection-oriented, ordered, and reliable transmission of message data that has record boundaries
  • SOCK_DGRAM: Unordered and unreliable transmission of messages