Last updated: Oct 15, 2019
IMAGE GALLERY (8)
What is socket?
A UNIX socket is an inter-process communication mechanism that allows bidirectional data exchange between processes running on the same machine.
IP sockets (especially TCP/IP sockets) are a mechanism allowing communication between processes over the network. In some cases, you can use TCP/IP sockets to talk with processes running on the same computer (by using the loopback interface).
- A Unix/Linux socket file is basically a two-way FIFO
- Socket is a special kind of file in linux like everything else.
- Connecting 2 processes to communicate
- Provides connectivity without the need of network through a socket file
- There are display server
- other examples are samba socketc, docker, libvirt, snapd, udev, systemd.journal
- Follows a client-server model
- Read more about socket on github
There is no commmand line tool to create sockets since a socket is always connect to a server which handles the requests sent to that socket.
How to find sockets and list them?
socket statistics command
ss --summary ss --tcp --all ss --udp --all find / -type s -print netstat -xl # Active UNIX domain sockets (only servers)
Usecases - Examples
Types of Files in Linux
- Plain File
- Or regular file which contains data in ASCII, binary or other encoded formats
Named sockets vs normal/un-named sockets
Why bother about sockets?
- Inter-process communication
- Network communication
- Peer to peer network
Analogy: Call on Telephone network
Pipes are a unidirectional IPC mechanism, with one end of a pipe opened for reading and the other end opened for writing.
Both the ls and more commands run without knowing they’re connected through a pipe. They simply read from file descriptor 0 (standard input) and write to file descriptor 1 (standard output).
- All descriptors point to active terminal session.
- Pipes follow the mechanism of IPC(inter provecc communication)
- Similar to other linux concepts like, signals, queues and sockets.
How does it happen?
- Virtual Filesystem VFS in Kernel space1
- Shortcoming, can only work in parent-child
Named PIPES are called FIFO
# blocking mkfifo fifo cal > fifo
ls | less
socketinbuilt module along with
socketserver - A framework for network servers
- SERVER :
- CLIENT :
- Fixed header-size
- Decide how to choose read/write buffer size!
pickleto seriase data before sending data over socket
stands for SOcket CAT