Unix vs BSD vs TCP vs Internet sockets?

前端 未结 1 1974
遥遥无期
遥遥无期 2021-02-04 19:00

I am reading The Linux Programming Interface and it describes several different types of socket used on Linux:

  • Unix domain
  • Berkeley
  • TCP
相关标签:
1条回答
  • 2021-02-04 19:33

    A socket is an abstraction. The tag definition used on SO for a socket is as good as any:

    An endpoint of a bidirectional inter-process communication flow. This often refers to a process flow over a network connection, but by no means is limited to such.

    So from that a major distinction are sockets that (1) use a network and (2) sockets that do not.

    Unix domain sockets do not use the network. Their API makes it appear to be (mostly) the same to the developer as a network socket but all the communication is done through the kernel and the sockets are limited to talking to processes on the machine upon which they are running.

    Berkeley sockets are what we know as network sockets on POSIX platforms today. In the past there were different lines of Unix development (e.g. Berkeley or BSD, System V or sysV, etc.) Berkeley sockets essentially won in the marketplace and are effectively synonymous with Unix sockets today.

    Strictly speaking there isn't a TCP socket. There are network sockets that can communicate using the TCP protocol. It's just a linguist shorthand to refer to them as a TCP socket to distinguish them from a socket using another protocol e.g. UDP, a routing protocol or whatnot.

    An "Internet" socket is a mostly a meaningless distinction. It's a socket using a network protocol. That eliminates Unix domain sockets, but most network protocols can be used to communicate on a LAN or the Internet, which is just collection of networks. (Though do note there are protocols specific to local networks as well as those that manage collections of networks.)

    0 讨论(0)
提交回复
热议问题