为什么洪流同行会发送一个空的消息?

时间:2016-02-26 11:09:55

标签: python tcp bittorrent

简短问题说明

request0 = "001360000000000\x400"  # Requesting for piece number 0
s.send(request0);
receivedPiece0 = s.recv(16384);
print len(receivedPiece0);  # prints 0

我收到的消息是空的。为什么呢?

更长的问题解释

我正在尝试编写一个BitTorrent客户端,现在我已经停留在那里了 收到unchoke消息后,我需要发送下载文件的请求。每次请求后我都会收到一条空信息。

握手并发送interested消息后,第一条消息 我收到的是:

# _ characters are just added by me in this post for  clarity,
# they were not present in the message
000250______000540001_______000540002_______000540000_________00011
bitfield    have piece 1    have piece 2    have piece 0      unchoke

然后我发送请求获得第0部分:

request0 = "001360000000000\x400"  # asking for block size of 2^14
s.send(request0);

并得到了回复:

receivedPiece0 = s.recv(16384);

以前最后一行抛出超时错误,因为我的请求是 形成错误。现在我收到一条空信息。为什么呢?

0 个答案:

没有答案