B
B
Bleno2019-06-02 13:29:53
Python
Bleno, 2019-06-02 13:29:53

How to handshake with a peer on a BitTorrent network?

Here is my code:

import socket
import time

sock = socket.socket()
sock.connect((peer_id, peer_port))

message = b'\x13BitTorrent protocol\x00\x00\x00\x00\x00\x00\x00\x00' + bytes('1A6948C96FA8302C74DA680C7360D1486A52B2F9'.lower(), encoding="UTF8") + b'66788486352714431784'

sock.send(message)

print('s')

while True:
    try:
        resp = sock.recv(len(message))
        print(resp)
        if resp != b'':
            break
    except:
        pass

In response from the peer, I get an empty string b''. And this line is constantly printed in the console
What's the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question