我正在尝试向对等方发送 BitTorrent 握手,但它不起作用。有人能弄清楚我做错了什么吗?len
应该会带着一些东西回来,但它目前是零。
require 'bencode'
require 'digest/sha1'
file = File.open('./python.torrent').read
info_hash = Digest::SHA1.hexdigest(a['info'].bencode)
# Here's what parsed_response['peers'] returns:
# [{"ip"=>"8.19.35.234", "peer id"=>"-lt0C20-\x90\xE0\xE6\x0E\xD0\x8A\xE5\xA2\xF2b(!",
# "port"=>9898}]
peer_id = parsed_response['peers'].first['peer id']
send_string = "\023BitTorrent protocol\0\0\0\0\0\0\0\0" << info_hash << peer_id
# ip and port are my current internet ip and 6881 respectively
client = TCPSocket.new ip, port
# What I'm sending over
client.send("\023BitTorrent protocol\0\0\0\0\0\0\0\0" << info_hash << peer_id, 0)
len = client.recv(1)
puts len
这是最后的send_string
样子: