Query DHT Server

拜拜、爱过 提交于 2019-12-05 06:49:46

问题


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...

Little example:

$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);

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

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


回答1:


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



来源:https://stackoverflow.com/questions/9340213/query-dht-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!