问题
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