如何写一个简单的BT软件的应用程序? [英] How to write a simple Bittorrent application?

查看:208
本文介绍了如何写一个简单的BT软件的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何写一个简单的BitTorrent应用程序。像世界你好使用的BitTorrent库什么的,我指的是应用程序了解的BitTorrent的工作的一个最简单的。我想preFER一个Python或C / C ++实现,但它可以是任何语言。平台是不是一个问题,要么,但我会preFER 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.

建议为库跟随,我已经下载一个源$ C ​​$ C(我认为官方的BitTorrent)从 - <一个href=\"http://sourceforge.net/projects/bittorrent/develop\">http://sourceforge.net/projects/bittorrent/develop.但是,我看到很多其他库在<一个href=\"http://en.wikipedia.org/wiki/Comparison_of_BitTorrent_clients#Libraries\">http://en.wikipedia.org/wiki/Comparison_of_BitTorrent_clients#Libraries.我想在这个AP preciate建议。

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易于得到安装python-libtorrent

蟒蛇code的一个非常简单的例子,用它来下载洪流:

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()
ses.listen_on(6881, 6891)

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

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

   state_str = ['queued', 'checking', 'downloading metadata', \
      'downloading', 'finished', 'seeding', 'allocating', 'checking fastresume']
   print '\r%.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, state_str[s.state]),
   sys.stdout.flush()

   time.sleep(1)

print h.name(), 'complete'

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

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