这篇文章纯粹是对http://cs.berry.edu这个大学的这个计算机的这段p2p框架代码的学习。代码结构灰常简单,逻辑清晰。并且基于这段代码实现了一个p2p文件共享系统。受益颇多。
一、p2p编程框架(及其python实现)
p2p框架代码: btpeer.py
p2p协议实现代码(即P2P文件共享协议): btfiler.py
P2P文件共享系统用户界面:filergui.py
二、
关于这个P2P框架,思考下面的问题:
1. 为啥self.sd = self.s.makefile('rw',0),为何不直接在socket上读写
2. 语法?
try:
...
except KeyboardInterrupt:
raise
except:
if self.debug:
traceback.print_exc()
return False
return True
3. self.sd.read(4):表示最多读取4个byte,若不到4个就少读一点罢了
4. BTPeerConnection::recvdata()中,
data = self.sd.read( min(2048, msglen-len(msg)) )
(1) 2048用意?
(2) self.sd.read(...)表示:最"多"读取的字节数
5. stabilizer的: 定期去ping每个peer, 将死亡的peer从self.peers中移除
(注:self.peerlock需要加锁)
参考文献:
p2p框架参考:
Peer-to-Peer Programming http://cs.berry.edu/~nhamid/p2p/index.html
P2P Programming Framework - Python http://cs.berry.edu/~nhamid/p2p/framework-python.html
File Sharing Application - Python http://cs.berry.edu/~nhamid/p2p/filer-python.html
编程参考:
socket模块 http://docs.python.org/2/library/socket.html
threading模块 http://docs.python.org/2.7/library/threading.html
python实现一个P2P文件发布,这段代码还没看过: http://blog.netzhou.net/?p=252
相关推荐
Python 3 Object Oriented Programming 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请...
在Python中进行P2P(Peer-to-Peer)网络编程是一项技术挑战,它涉及到网络通信、多线程处理以及文件传输等多个方面的知识。本项目实现了一个基础的P2P网络模型,包括一个中心服务器和三个对等节点。下面将详细阐述...
《Programming Python 中文第四版》是一本深入介绍Python编程的权威指南,专为那些希望学习或深化Python编程技能的人设计。这本书的第四版更新了内容,涵盖了最新的Python版本特性,确保读者能掌握当前最前沿的...
《Python库Robotframework-SSHLibrary 3.5.0rc1详解》 在Python的世界里,库是开发者的重要工具,它们极大地丰富了Python的功能并提高了开发效率。本篇文章将深入探讨一个名为`robotframework-sshlibrary`的Python...
面向对象编程(Object-Oriented Programming,简称 OOP)是一种编程范式,它将程序设计围绕“对象”进行组织。在 Python 中,几乎一切都是对象。OOP 提供了一种将现实世界中的实体映射到软件设计中的方法。本章节...
No Starch Press,2014出版, Black Hat Python, Python Programming for Hackers and Pentesters
《QT5_PYTHON_GUI_PROGRAMMING_COOKBOOK.pdf》这本书不仅适合初学者入门,也对有一定经验的开发者有很高的参考价值。通过学习,读者不仅可以掌握PyQt5的基本使用,还能深入理解GUI编程的设计思想和最佳实践,为构建...
Learn the Python Programming Language - Today! What is Python? What do you need to know about it? How do you get started learning this essential programming language? When you purchase Python: ...
[Python应用核心编程(第3版)].(Core.Python.Applications.Programming).
Python: Practical Python Programming For Beginners and Experts English | 9 July 2016 | ISBN: 1535192976 | 170 Pages Start work on your website, app, or search engine today with this practical Python ...
python网络编程,适用于网络编程方向的同学,书中采用的是python3的代码。
python-dependency-injector, python的依赖注入 microframework 依赖注入器- python的依赖注入 microframework依赖注入器是 python的依赖注入 microframework 。 它被设计成统一的开发人员友好工具,帮助实现形式化...
**Robot Framework调用Python类方法**是自动化测试中的一种常见技术,Robot Framework是一个高级的通用自动化框架,而Python是其背后的编程语言,提供了丰富的库和功能。本篇将深入讲解如何利用Robot Framework进行...
Chapter 1, Sockets, IPv4, and Simple Client/Server Programming, introduces you to Python's core networking library with various small tasks and enables you to create your first clientserver ...
How to build useful, real-world applications in the Python programming language Key Features Deliver scalable and high-performing applications in Python. Delve into the great ecosystem of Python ...
本书共8章,涵盖的内容有Python语言的基本语法、Python常用IDE的使用、Python第三方模块的导入使用、Python爬虫常用模块、Scrapy爬虫、Beautiful Soup爬虫、Mechanize模拟浏览器和Selenium模拟浏览器。本书所有源...