这篇文章纯粹是对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功能书! Functional programming defines a computation using expressions and evaluation—often encapsulated in function definitions. It de-emphasizes or avoids the complexity of state...
programming python 4th edition, python学习教程,python应用
programming python 中文第四版
Python 3 Object Oriented Programming.pdf
If you're a Python developer or a system administrator with Python experience and you're looking to take your first steps in network programming, then this book is for you. Basic knowledge of Python ...
Foundations of Python Network Programming, Third Edition, covers all of the classic topics found in the second edition of this book, including network protocols, network data and errors, email, server...
Python.GUI.Programming.Cookbook
Python 3 Object oriented Programming,面向对象编程。
Core.Python.Applications.Programming 高清完整版PDF下载
Apress, Foundations of Python Network Programming,Python网络编程基础,第三版,2014
In Core Python Applications Programming, you will take all the Python knowledge gained elsewhere and develop new skills, building up a toolset with which you’ll be able to use Python for a variety of...
Python network programming.pdf Python network programming.pdf 中文名-- python网络编程
No Starch Press,2014出版, Black Hat Python, Python Programming for Hackers and Pentesters
Packt.Python.Network.Programming.Cookbook.2nd.Edition.2017
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 ...
Master efficient parallel programming to build powerful applications using Python About This Book Design and implement efficient parallel software Master new programming techniques to address and ...