Unix vs BSD vs TCP vs Internet套接字?

时间:2022-02-25 11:10:23

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

我正在阅读Linux编程接口,它描述了Linux上使用的几种不同类型的套接字:

  • Unix domain
  • Berkeley
  • TCP
  • Internet

One of the things the book said is that if you want to communicate between remote hosts, you couldn't use Unix domain sockets because they are for IPC on the same host. You have to use "Internet" sockets.

本书所说的一件事是,如果你想在远程主机之间进行通信,你就不能使用Unix域套接字,因为它们适用于同一主机上的IPC。你必须使用“互联网”套接字。

However, I am still a little confused how this relates with "TCP" sockets, Berkeley sockets and the other 2? What is their relationship? Why would you have an Internet socket as well as a TCP socket?

但是,我仍然有点困惑这与“TCP”套接字,伯克利套接字和其他2有什么关系?他们的关系是什么?为什么你会有一个Internet套接字以及一个TCP套接字?

In short I am trying to understand all (have I missed any out?) the various different types of Unix sockets and under what circumstances I would use them?

总之,我试图了解所有(我错过了什么?)各种不同类型的Unix套接字以及在什么情况下我会使用它们?

1 个解决方案

#1


11  

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

套接字是一种抽象。 SO上用于套接字的标记定义与以下任何内容一样好:

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.

因此,主要的区别是(1)使用网络和(2)不使用网络的套接字。

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.

Unix域套接字不使用网络。它们的API使得开发人员(大多数)看起来与网络套接字相同,但所有通信都是通过内核完成的,而套接字仅限于与运行它们的机器上的进程通信。

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.

Berkeley套接字是我们今天所知的POSIX平台上的网络套接字。在过去,有不同的Unix开发线(例如Berkeley或BSD,System V或sysV等).Berkeley套接字基本上在市场上获胜,并且现在实际上是Unix套接字的同义词。

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.

严格来说,没有TCP套接字。有些网络套接字可以使用TCP协议进行通信。它只是一种语言学家的简写,将它们称为TCP套接字,以使用其他协议将它们与套接字区分开,例如UDP,路由协议或诸如此类的东西。

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.)

“互联网”套接字大多是无意义的区别。它是使用网​​络协议的套接字。这消除了Unix域套接字,但大多数网络协议可用于在LAN或Internet上进行通信,这只是网络的集合。 (尽管请注意,有一些特定于本地网络的协议以及管理网络集合的协议。)

#1


11  

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

套接字是一种抽象。 SO上用于套接字的标记定义与以下任何内容一样好:

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.

因此,主要的区别是(1)使用网络和(2)不使用网络的套接字。

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.

Unix域套接字不使用网络。它们的API使得开发人员(大多数)看起来与网络套接字相同,但所有通信都是通过内核完成的,而套接字仅限于与运行它们的机器上的进程通信。

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.

Berkeley套接字是我们今天所知的POSIX平台上的网络套接字。在过去,有不同的Unix开发线(例如Berkeley或BSD,System V或sysV等).Berkeley套接字基本上在市场上获胜,并且现在实际上是Unix套接字的同义词。

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.

严格来说,没有TCP套接字。有些网络套接字可以使用TCP协议进行通信。它只是一种语言学家的简写,将它们称为TCP套接字,以使用其他协议将它们与套接字区分开,例如UDP,路由协议或诸如此类的东西。

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.)

“互联网”套接字大多是无意义的区别。它是使用网​​络协议的套接字。这消除了Unix域套接字,但大多数网络协议可用于在LAN或Internet上进行通信,这只是网络的集合。 (尽管请注意,有一些特定于本地网络的协议以及管理网络集合的协议。)