wiki

Help! I'm trapped in a wiki!

Site Tools


linux:sockets

Sockets

Sockets are a way for the kernel to communicate with the network.

Sockets need to have an IP address and port binded to them. Once you do this, you can write to and read from the socket just like a regular file to send and receive data over the network.

There are four common types of AF_INET (internet) sockets:

  • SOCK_STREAM: TCP
  • SOCK_DGRAM: UDP
  • SOCK_RAW
    • This only sets up IP packets, you’ll need to bring your own protocol (like ping does with ICMP messages)

There are also AF_UNIX sockets, or Unix domain sockets, which allow interprocess communication. (docker uses this)
You can make a stream or datagram socket (just like internet sockets) however here, datagram just means chunks of data which are always reliable, unlike UDP’s datagrams.

With Unix domain sockets you can restrict access using regular file permissions. This is one way docker uses unix domain sockets: untrusted containers can’t write to the sockets.

See also

linux/sockets.txt · Last modified: by 127.0.0.1