Difference between UNIX domain STREAM and DATAGRAM sockets?

前端 未结 4 484
一生所求
一生所求 2021-01-30 00:55

This question is NOT for the difference between STREAM type and DATAGRAM type INTERNET sockets. I know that STREAM sockets use TCP, Datagram sockets use UDP and all the T

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-30 01:33

    The main difference is that one is connection based (STREAM) and the other is connection-less (DGRAM) - the difference between stream and packet oriented communication is usually much less important.

    With SOCK_STREAM you still get all the connection handling, i.e. listen/accept and you can tell if a connection is closed by the other side.

    Note that there is also a SEQPACKET socket type that's still connection oriented, but preserves message boundaries (which might save you from implementing a message-oriented layer on top of a STREAM socket).

    I would expect data transfer performance to be similar for all of these types, the main difference is just what semantics you want.

提交回复
热议问题