如何编写(实现)网络协议(规范)

发布于 2024-12-05 15:09:37 字数 118 浏览 1 评论 0原文

如何编写(实现)网络协议,例如 ftp、bittorrent、adc、gnutella 等? 使用了什么语言?哪里下载源码?我读到使用了boost.asio,boost.spirit,beep,输入长度值,什么更好的选择?

How to write(implement) a network protocols such as ftp, bittorrent, adc, gnutella etc?
What were used language? where donwloads sources? I was reads to used boost.asio, boost.spirit, beep, type length value, what better choose?

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

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

发布评论

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

评论(1

找个人就嫁了吧 2024-12-12 15:09:37

您是在谈论实施现有协议还是创建新协议?我假设是前者。

您首先需要的是规格。标准互联网协议由 RFC 指定。例如,FTP 由 RFC 959 指定。你提到的其他协议不是标准,但它们可能仍然有规范;例如,BitTorrent 有一个,尽管它不是很好(有一个 尝试澄清)。

您需要的第二件事是具有用于执行套接字 IO 的 API 的语言。每一种严肃的语言都有一种。例如,在 Java 中,它位于 java.lang. NET 包。你可以使用任何语言,只要它有这样的API。

然后你只需要坐下来遵循规范,并编写可以按照规范中定义的格式发送和接收消息的代码。

或者,您可以查找该协议的现有实现并使用它。没有集中的地方可以找到协议的实现;您的语言的标准库将包含一些(例如,Java 有 FTP、HTTP、SMTP、IIOP,也许还内置了其他一些库),并且您可以下载其他库作为第三方包。

你提到了一些图书馆。 Boost.asio 是一个 C++ 套接字 IO 库。它是基本操作系统 API 之上的一层,旨在使其变得更容易。 Boost.spirit是一个解析器库;您可以使用它来解析协议,尽管这对于更复杂的协议来说只是一个好的举措。 BEEP 是一个协议,或者更确切地说是构建协议的框架;它只会帮助您在 BEEP 之上实现协议,而大多数协议都不是。标签长度值是一种数据编码方式,某些协议使用,但不是全部。

Are you talking about implementing an existing protocol, or creating a new one? I will assume the former.

The first thing you need is the specification. Standard internet protocols are specified by RFCs. For example, FTP is specified by RFC 959. The other protocols you mention are not standards, but they may still have specifications; for example, BitTorrent has one, although it isn't very good (there's an attempt to clarify it).

The second thing you need is a language with an API for doing socket IO. Every serious language has one. In Java, for example, it's in the java.net package. You can use any language, as long as it has such an API.

Then you just need to sit down and follow the specification, and write code which can send and receive messages in the format defined in the specification.

Alternatively, you could look for an existing implementation of the protocol, and use that. There is no centralised place to find implementations of protocols; your language's standard library will contain some (for example, Java has FTP, HTTP, SMTP, IIOP, and maybe some others built in), and you may be able to download others as third-party packages.

You mention a few libraries. Boost.asio is a library for socket IO in C++. It's a layer on top of the basic operating system API that aims to make it easier. Boost.spirit is a parser library; you could use it to parse a protocol, although that would only be a good move for the more complex protocols. BEEP is a protocol, or rather a framework for building protocols; it would only help you with a protocol implemented on top of BEEP, which most protocols are not. Tag-length-value is a style of data encoding, which some protocols use, but not all.

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