What is a Socket?
Recently, while reviewing the FAQ, I came across the question “What’s a Socket?” For those who are not familiar, I shall explain.
In brief, a Unix Socket (technically, the correct name is Unix domain socket, UDS) allows communication between two different processes on either the same machine or different machines in client-server application frameworks. To be more precise, it’s a way of communicating among computers using a standard Unix descriptors file.
Every UNIX systems Input/Output action is executed by writing or reading the descriptor file. A Descriptor file is an open file, which is associated with an integer. It can be a network connection, text file, terminal or something else. It looks and behaves much like a low-level file descriptor. This happens because the commands like read () and write () works with the same way they do with the files and pipes.
Types of Sockets
There are four types of sockets.
The first 2 are more commonly used than the second 2 types :
Everything you need to grow your career.
With your free Red Hat Developer program membership, unlock our library of cheat sheets and ebooks on next-generation application development.SIGN UP
Delivery in a networked environment is guaranteed. These use TCP (Transmission Control Protocols) for data transmission.
A stream socket is a type of interprocess communication socket or network socket, which provides a connection-oriented, sequenced, and unique flow of data without record boundaries, with well-defined mechanisms for creating and destroying connections and for detecting an error.
A stream socket transmits data reliably, in order and with out-of-band capabilities. If you send three items “A, B, C” then the receiver will receive it in the same order.
Delivery in a networked environment is not guaranteed. These UDP (User Datagram Protocols) for data transmission.
These provide user access to the underlying communication protocols, which support socket abstractions. They are not intended for general use.
Sequenced Packet Sockets (SPS)
Sequenced Packet Sockets similar to Stream Sockets, with the exception that record boundaries are preserved. SPP interface is only provided as part of the network system socket abstraction and is very important in most serious network system applications.
It allows the user to modify the SP Protocols header on a packet or a group of packets, either by writing a prototype header along whatever data is to be sent or by specifying a default header to be used with all outgoing data.
SPS allows the user to receive the header on incoming packets.
The process defined above is to communicate between the same types of sockets. But there is no restriction in communicating between the different types of socket.
You can find more general information about Unix Sockets here.
Whether you are new to Containers or have experience, downloading this cheat sheet can assist you when encountering tasks you haven’t done lately.