还有哪些套接字 API 可用?这些 Socket API 之间有什么区别?

发布于 2024-08-17 18:57:10 字数 857 浏览 8 评论 0原文

每个人都将其称为 C 语言的套接字编程或网络编程,我们通过包含 sys/socket.h & 来开始使用它。 netinet/in.h。我们认为这是 100% 真实的。但是当我看到这本书

Internetworking With TCP/IP Volume III: Client-Server Programming and Applications 时,我的脑海中出现了问题,该书有 4 个不同的版本

  1. Linux/POSIX 套接字
  2. AT&T TLI(传输层接口)套接字
  3. BSD(伯克利)套接字
  4. Window 套接字

我很困惑。这清楚地表明Socket API没有标准。

我也很惊讶地看到 sys/socket.h & netinet/in.hhttp://en.wikipedia.org/wiki/Berkeley_sockets" rel="nofollow noreferrer">http:// /en.wikipedia.org/wiki/Berkeley_sockets。我现在更困惑了。

  1. 为什么没有一个标准呢?
  2. 还有哪些套接字 API 可用?
  3. 这些 Socket API 之间有什么区别?
  4. 当人们说“C 网络编程”/“套接字编程”时,他们到底指的是什么?
  5. 有更多信息的链接吗?

Everyone referred to it as Socket Programming or Network Programming in C and we started using it by using by including sys/socket.h & netinet/in.h. We thought it was 100% true. But question raised in my mind when I saw this book

Internetworking With TCP/IP Volume III: Client-Server Programming and Applications, which was available in 4 different versions

  1. Linux/POSIX Sockets
  2. AT&T TLI (Transport Layer Interface) Sockets
  3. BSD (Berkeley) sockets
  4. Window Sockets

I'm confused. This clearly shows that there is no standard for Socket API.

also I'm surprised to see sys/socket.h & netinet/in.h which are part of POSIX C library in the http://en.wikipedia.org/wiki/Berkeley_sockets . I'm more confused now.

  1. Why isn't there a standard for this?
  2. What more socket APIs are available?
  3. What are the differences between each of these Socket API?
  4. When People say Just "Network Programming in C" / "Socket Programming" what exactly they are referring to?
  5. Links for any further information?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

可爱咩 2024-08-24 18:57:11

为什么没有一个标准?

事实上的标准是 BSD 套接字,Linux、POSIX 和 Windows 套接字 API 均基于该标准。

还有哪些套接字 API 可用?

没有什么仍然被广泛使用的。在 BSD 套接字及其衍生品占领世界之前,有很多套接字。剩下的大多数可能都在嵌入式世界中,随着主流操作系统继续吞噬越来越多的嵌入式市场,即使这些也正在消失。

这场战斗到20世纪90年代中期已经基本结束。 BSD 套接字获胜。

这些 Socket API 之间有什么区别?

BSD、Linux 和 POSIX 变体之间存在细微差别,但并不比 Unixy 操作系统之间的任何其他差别更严重。

他们之所以有这本书的 Linux/POSIX 版本,可能更多的是出于营销而不是技术方面的考虑。它回答了出版商可能经常看到的一个问题:“为什么我需要一本 BSD 书,我运行的是 Linux,而不是 BSD!”或者,现在更常见的是:“什么是 BSD?”

从 10,000 英尺的角度来看,Winsock 与 BSD 套接字有很大不同,但因为它是 BSD 套接字的相当严格的超集,所以您仍然可以将您的知识转移过去。大多数差异都是对 BSD 套接字的纯粹扩展,主要与 Windows 内核体系结构和 Windows 程序通常构建方式的差异有关。例如,第一个真正大的扩展是异步套接字,这使得在单线程 Windows GUI 程序中使用套接字比使用纯 BSD 套接字更容易。后来的扩展支持 NT 派生内核中可用的特殊功能,这些功能在 Unixy 系统中没有简单的模拟,例如事件对象和重叠 I/O。

无论如何,在某些 Unixy 系统中也有对普通旧式 BSD 套接字的扩展,例如 Solaris 和其他系统中的 aio_*() 内容。

如果您的程序必须与许多系统源兼容,您要么忽略这些差异并根据所有这些系统共享的公共基础进行编程,要么构建某种类型的转换层,让您透明地使用平台功能。例如,Apache 就采用后者,利用每个平台上最快的网络功能,而核心 Web 服务器代码并不关心网络是如何完成的。许多其他程序选择可移植路径,因为它们对性能并不关键,因此节省程序员的时间更为重要。

当人们说“C 网络编程”/“套接字编程”时,他们到底指的是什么?

BSD 套接字或某些变体。

有更多信息的链接吗?

Winsock 程序员常见问题解答。具体来说,您可能需要查看其资源部分以及常见问题解答文章BSD 套接字兼容性

(免责声明:我是常见问题解答的维护者。)

Why isn't there a standard for this?

The de facto standard is BSD sockets, upon which the Linux, POSIX and Windows sockets APIs are based.

What more socket APIs are available?

Nothing that's still widely used. Before BSD sockets and its derivatives took over the world, there were many. Most of the ones that remain are probably in the embedded world, and even those are going away as mainstream OSes continue to swallow more and more of the embedded market.

This battle was pretty much fought and over by the mid 90's. BSD sockets won.

What are the differences between each of these Socket API?

There are minor differences among the BSD, Linux and POSIX variants, nothing more serious than any other differences among Unixy operating systems.

The reason they have a Linux/POSIX version of the book probably has more to do with marketing than anything technical. It answers a question the publisher probably saw a lot, "Why do I need a BSD book, I'm running Linux, not BSD!" Or, more commonly these days: "What's BSD?"

From a 10,000 foot view, Winsock is very different from BSD sockets, but because it's a fairly strict superset of BSD sockets, you can still move your knowledge over. Most of the differences are pure extensions to BSD sockets, mostly to do with the differences in the Windows kernel architecture and the way Windows programs are typically built. For instance, the first really big extension was asynchronous sockets, which makes it much easier to use sockets in a single-threaded Windows GUI program than using pure BSD sockets. Later extensions support special features available in the NT derived kernels that have no simple analog in Unixy systems, like event objects and overlapped I/O.

For what it's worth, there are extensions to plain old BSD sockets in some Unixy systems, too, like the aio_*() stuff in Solaris and other systems.

If your program has to be source compatible with many systems, you either ignore these differences and program to the common base shared by all these systems, or you build some kind of translation layer that lets you use platform features transparently. Apache does the latter for instance, making use of the fastest networking features on each platform, while the core web server code doesn't care exactly how the networking gets done. Many other programs choose the portable path, since they're not performance critical, and saving programmer time is therefore more important.

When People say Just "Network Programming in C" / "Socket Programming" what exactly they are referring to?

BSD sockets or some variant.

Links for any further information?

The Winsock Programmer's FAQ. Specifically, you might want to look at its resources section, and the FAQ article BSD Sockets Compatibility.

(Disclaimer: I'm the FAQ's maintainer.)

手长情犹 2024-08-24 18:57:11

Linux、BSD 和 Windows 套接字 API(至少;我不知道 AT&T TLI API)彼此非常相似。例如,Windows API 最初是基于 BSD API 的。

The Linux, BSD, and Windows sockets APIs (at least; I don't know about the AT&T TLI API) are pretty similar to each other. The Windows API, for example, is/was originally based on the BSD API.

初与友歌 2024-08-24 18:57:11

为什么没有一个标准?

有。你说出了几个。任何人都可以发布一个“标准”,不需要只有一个,也不需要某个有权授予“唯一真道”的控制机构。就网络而言,真正的标准是网络协议本身。每个人都必须与他们进行互操作,否则将无法协同工作。任何给定平台实现 API 来实现该目标的方式都可能有所不同。

这些 Socket API 之间有什么区别?

Linux/POSIX/BSD 都是类似的。 Windows 略有不同,但由于它仍然必须支持底层协议,因此功能最终几乎相同。老实说,我不确定谁再使用 AT&T TLI(如果他们曾经使用过)。

还有哪些套接字 API 可用?

可能有很多,但问题是谁还在使用它们。 IBM 曾经有很多,当时大多数其他主要制造商也是如此。但我认为这些大部分已经被扔进了历史垃圾箱,因为大多数人都使用 TCP。

当人们说“C 网络编程”/“套接字编程”时,他们到底指的是什么?

没有什么精确的。从技术上讲,C 语言对网络编程一无所知。然而,许多供应商(例如 Unix、Linux、Windows 等)提供 C 库来执行网络操作,因此有您上面提到的许多 API。

Why isn't there a standard for this?

There are. You named several. Anyone can publish a "standard", there doesn't need to be just one nor is there some controlling authority with the power to confer "The One True Way". In terms of networking the real standards are the network protocols themselves. Everyone must inter-operate with them or nothing works together. How any given platform implements the APIs to accomplish that goal can vary.

What are the differences between each of these Socket API?

Linux/POSIX/BSD are all similar. Windows is a little different but since it still has to support the underlying protocols the functionality ends up being pretty much the same. Honestly I am not sure who uses AT&T TLI anymore, if they ever did.

What more socket APIs are available?

There are probably plenty but it is a question of who uses them anymore. IBM used to have a bunch and so did most every other major manufacturer back in the day. But I think these for have for the most part been retired to the history dust bin since most everyone uses TCP.

When People say Just "Network Programming in C" / "Socket Programming" what exactly they are referring to?

Nothing precise. Technically the C language doesn't know anything about network programming. However many vendors (e.g. Unix, Linux, Windows, etc) provide C libraries to perform networking operations, hence the many APIs you noted above.

予囚 2024-08-24 18:57:11

TLI 接口实际上与 OSI 一致。 Novell 也曾一度发货。它已经过时了。 Linux 和 Winsock API 都基于 BSD API,对于 Linux 来说非常接近,而对于 Winsock 来说则不太如此。这两种情况在实现上也存在细微的差异。

The TLI interface is actually aligned to OSI. Novell were also shipping it at one time. It is obsolete. The Linux and Winsock APIs are based on the BSD API, closely in the case of Linux, less so in the case of Winsock. There are also small implementation differences in both cases.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文