简体   繁体   中英

python bittorrent peer protocol unable to connect to any peers

I"m trying to learn more about bittorrent protocols, and i'm successful in obtaining a list of peers via UDP.

Where I am having trouble with, is making a connection to the peer IPs itself (even before sending a handshake). i'm usually met with errors such as: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

I've read up as much as I could, and according to most documentations:

After receiving a peer IP and port-number from the tracker, our client will to open a TCP connection to that peer. Once the connection is open, these peers will start to exchange messages using the peer protocol.

However, I don't think this is as simple as

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ip, port))  # where ip and port is obtained from the list of IPs and PORTS from the tracker
## This above 2 lines of codes is met with a connection attempt failed error. 

According to this p2p question on stackoverflow , there is a bunch of low level things that will need to be done in order for me to connect to the list of peers i've obtained from the UDP announce trackers.

How should I go about in making a connection to the peers?

You can read this: http://www.bittorrent.org/beps/bep_0003.html .

If you want to make a connection, you need to connect by peer protocol / peer wire protocol. So you need to use utp or TCP, the pure UDP can not work. And the message format need to follow protocols.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM