Unix,BSD,TCP,Internet套接字? [英] Unix vs BSD vs TCP vs Internet sockets?

查看:149
本文介绍了Unix,BSD,TCP,Internet套接字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

  • Unix域
  • 伯克利
  • TCP
  • 互联网

这本书说的一件事是,如果要在远程主机之间进行通信,则不能使用Unix域套接字,因为它们用于同一主机上的IPC.您必须使用"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.

但是,我仍然有些困惑,这与"TCP"套接字,伯克利套接字和其他2个套接字有什么关系?他们是什么关系?为什么要有Internet套接字和TCP套接字?

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?

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

推荐答案

套接字是一种抽象. SO上用于套接字的标签定义与任何标签一样好:

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.

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

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

Unix domain 套接字不使用网络.他们的API使开发人员看上去与网络套接字几乎相同,但是所有通信都是通过内核完成的,套接字仅限于与正在运行它们的计算机上的进程进行通讯.

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.

伯克利套接字是当今在POSIX平台上称为网络套接字的东西.过去,Unix开发的方式各不相同(例如Berkeley或BSD,System V或sysV等),Berkeley套接字在市场上基本上是赢家,并且实际上是当今Unix套接字的代名词.

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.

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

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.

"Internet"套接字几乎是毫无意义的区别.它是使用网​​络协议的套接字.这消除了Unix域套接字,但是大多数网络协议可用于在LAN或Internet上进行通信,而LAN或Internet只是网络的集合. (不过请注意,有些协议专用于本地网络以及管理网络集合的协议.)

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,BSD,TCP,Internet套接字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆