# Unix Sockets

Socket addressing allows you to do interprocess communication. Unix domain sockets increase efficiency by bypassing the operating system’s network stack, eliminating the overhead of traffic routing.

### Types

1. **Stream Sockets (SOCK\_STREAM)**:
    
    * Stream sockets provide a connection-oriented, reliable, two-way communication channel between processes.
        
    * This type of socket is typically used with the Transmission Control Protocol (TCP) for reliable data transmission.
        
    * Communication occurs in a continuous stream of bytes, preserving message boundaries.
        
2. **Datagram Sockets (SOCK\_DGRAM)**:
    
    * Datagram sockets provide connectionless, unreliable communication between processes.
        
    * They are commonly used with the User Datagram Protocol (UDP), where messages are sent in discrete packets called datagrams.
        
    * Datagram sockets do not guarantee the delivery or ordering of messages, making them suitable for applications where low overhead and speed are prioritized over reliability.
        
3. **Raw Sockets (SOCK\_RAW)**:
    
    * Raw sockets allow applications to directly access lower-level network protocols, such as IP, ICMP, or ICMPv6.
        
    * They provide full control over the packet headers, allowing applications to implement custom protocols or perform low-level network tasks.
        
    * Raw sockets are typically used for network diagnostic tools, protocol development, or network sniffing applications.
        
4. **Sequential Packet Sockets (SOCK\_SEQPACKET)**:
    
    * Sequential packet sockets provide a connection-oriented, reliable communication channel similar to stream sockets.
        
    * However, they preserve message boundaries like datagram sockets, ensuring that the data sent by one peer will be received as a whole message by the other peer.
        
    * Sequential packet sockets are not as commonly used as stream or datagram sockets but can be useful in certain scenarios where message boundaries are critical.
