Unix socket, SOCK_SEQPACKET vs SOCK_DGRAM

前端 未结 5 1937
一生所求
一生所求 2021-02-01 12:36

It seems there\'s atleast 3 different local/unix socket types (AF_UNIX) , SOCK_STREAM, SOCK_DGRAM and SOCK_SEQPACKET.

<
5条回答
  •  北荒
    北荒 (楼主)
    2021-02-01 12:54

    I think the main difference here is that SOCK_SEQPACKET is conneciton-oriented, while SOCK_DGRAM is not.

    This will mostly matter on the server side of the connection (the process that listens on the UNIX socket) when there are multiple client processes talking to it:

    With SOCK_DGRAM, you would get interleaved client datagrams directly on the listening socket. With SOCK_SEQPACKET, you would spawn a separate client socket for each client using accept, thus receiving datagrams from each client separately.

    Quoting man 3 accept:

    The accept() system call is used with connection-based socket types (SOCK_STREAM, SOCK_SEQPACKET).

提交回复
热议问题