查询 DHT 服务器

2022-01-22 00:00:00 udp php dht

我正在尝试对 DHT 服务器进行简单查询.

I'm trying to make a simple query to a DHT server.

我正在尝试做一个简单的示例来测试对服务器的查询,但我没有得到服务器以任何形式的响应...

I'm trying to make a simple simple example to test queries to the servers, but I don't get a response from the server in any form...

小例子:

$socket = fsockopen("udp://router.bittorrent.com", 6881, $errno, $errstr, 3);
fwrite($socket, 'p'); $Head = fread($socket, 4);
$CheckStatus = socket_get_status($socket);      
if($CheckStatus["unread_bytes"] == 0)
{
    return 0;
}   
$do = 1;
while($do)
{
    $str = fread($socket,1);
    $stats .= $str;
    $status = socket_get_status($socket);
    if($status["unread_bytes"] == 0)
    {
        $do = 0;
    }
}
fclose($socket);

关于 DHT 服务器查询的信息在这里:http://www.bittorrent.org/beps/bep_0005.html#dht-queries

The info about the queries in DHT server is here: http://www.bittorrent.org/beps/bep_0005.html#dht-queries

但我不明白如何使用 PHP 来实现.这可能吗?我的代码有什么问题?

But I don't understand how make this with PHP. Is this possible? What's the problem with my code?

推荐答案

正如 8472 提到的,您的客户端正在发送 p,这不是一个有效的查询.要查看有效的查询格式,请查看此处:bep 005

As the8472 mentions, your client is sending p, which is not a valid query. To see valid query formats, look here: bep 005

相关文章