如何编写一个简单的 Bittorrent 应用程序?

How to write a simple Bittorrent application?(如何编写一个简单的 Bittorrent 应用程序?)
本文介绍了如何编写一个简单的 Bittorrent 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写一个简单的 bittorrent 应用程序.类似于使用 bittorrent 库的hello world",我的意思是理解 bittorrent 工作的最简单的应用程序.我更喜欢 python 或 C/C++ 实现,但它可以是任何语言.平台也不是问题,但我更喜欢 Linux.

How to write a simple bittorrent application. Something like a "hello world" using a bittorrent library, I mean a simplest of the application to understand the working of bittorrent. I would prefer a python or a C/C++ implementation, but it can be any language. Platform is not an issues either, but i would prefer Linux.

对图书馆的建议,我已经从 http://sourceforge.net/projects/bittorrent/develop.但是,我在 http://en.wikipedia.org/wiki/Comparison_of_BitTorrent_clients 看到了很多其他库#图书馆.我会很感激这方面的建议.

Recommendations for the library to follow, I have downloaded the source code for one (i think official bittorrent) from - http://sourceforge.net/projects/bittorrent/develop. But, I see a lot of other libraries at http://en.wikipedia.org/wiki/Comparison_of_BitTorrent_clients#Libraries. I would appreciate recommendations on this.

如果您只有一台笔记本电脑,如何测试应用程序.

How to test an application if all you have is one laptop.

推荐答案

你应该试试 libtorrent (rasterbar).http://libtorrent.org

You should try libtorrent (rasterbar). http://libtorrent.org

如果你想用 python 编写你的客户端,在 linux 上,安装它:

If you want to write your client in python, on linux, install it with:

sudo apt-get install python-libtorrent

一个非常简单的python代码示例,用它来下载种子:

A very simple example of python code to use it to download a torrent:

import libtorrent as lt
import time
import sys

ses = lt.session({'listen_interfaces': '0.0.0.0:6881'})

info = lt.torrent_info(sys.argv[1])
h = ses.add_torrent({'ti': info, 'save_path': '.'})
s = h.status()
print('starting', s.name)

while (not s.is_seeding):
    s = h.status()

    print('
%.2f%% complete (down: %.1f kB/s up: %.1f kB/s peers: %d) %s' % (
        s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000,
        s.num_peers, s.state), end=' ')

    alerts = ses.pop_alerts()
    for a in alerts:
        if a.category() & lt.alert.category_t.error_notification:
            print(a)

    sys.stdout.flush()

    time.sleep(1)

print(h.status().name, 'complete')

这篇关于如何编写一个简单的 Bittorrent 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Leetcode 234: Palindrome LinkedList(Leetcode 234:回文链接列表)
How do I read an Excel file directly from Dropbox#39;s API using pandas.read_excel()?(如何使用PANDAS.READ_EXCEL()直接从Dropbox的API读取Excel文件?)
subprocess.Popen tries to write to nonexistent pipe(子进程。打开尝试写入不存在的管道)
I want to realize Popen-code from Windows to Linux:(我想实现从Windows到Linux的POpen-code:)
Reading stdout from a subprocess in real time(实时读取子进程中的标准输出)
How to call type safely on a random file in Python?(如何在Python中安全地调用随机文件上的类型?)