如何构建 Python p2p 应用程序?

发布于 2024-12-22 11:09:53 字数 175 浏览 3 评论 0原文

我是 Python 编程新手,对套接字有一些了解。我在网络上找不到任何简单的实现。其基本功能应包括:

  • 简单的聊天
  • 文件共享
  • 对等查找

我如何开始,p2p 模型应该是什么?我不想使用任何库,例如 Twisted,因为它很复杂。

I am new to Python programming and have covered sockets a bit. I couldn't find any simple implementation on the web. Its basic functionality should cover:

  • simple chat
  • file sharing
  • peer lookup

How do I start, and what should be the p2p model? I don't want to use any library such as Twisted, as it is complex.

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

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

发布评论

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

评论(2

我不是你的备胎 2024-12-29 11:09:53

如果您愿意直接使用套接字,您可以自己编写该库。让每个节点包含定期更新的对等点列表,并将每个节点设置为向中央服务器通告其存在。您需要研究网络遍历算法、哈希表等,但这是可以完成的。正如 Xavier 所说,首先从简单开始,然后让它快速运行 - 然后添加功能。

为了简化起见,您可以首先实施手动对等互连;首先让文件共享和聊天正常工作,然后再添加对等/发现。

这里有相当多的工作,但如果你写了所有内容,可能会更容易实现 - 所有内容都更容易理解!但是,图书馆的好处是很多工作都是为您完成的。这是一个权衡:)

You could write the library yourself, if you're willing to work with sockets directly. Have each node contain a list of peers that is regularly updated, and set each node to advertise its presence to a central server. You'd need to look into network traversal algorithms, hash tables, etc but it could be done. As Xavier says, start simple first, and get it working quickly - then add features.

For simplification you could implement manual peering to start with; get file sharing and chat working first, and then add peering/discovery later.

There is quite a bit of work here but it may be more achievable if you've written everything - everything is easier to understand! But, the upside of a library is a lot of the work is done for you. It's a trade-off :)

留蓝 2024-12-29 11:09:53

对于对等查找,我将从一个简单的中央服务器开始,对于简单的聊天和文件共享,我将使用 HTTP 协议的衍生版本。

for the peer lookup I would begin with a simple central server and for simple chat and file sharing I would use a derivate of HTTP protocol.

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