1

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?

Ry-
  • 218,210
  • 55
  • 464
  • 476
Zenth
  • 769
  • 2
  • 7
  • 23
  • Any DHT Torrent querry example here? – Zenth Feb 20 '12 at 17:06
  • 1
    I would advise against using PHP for this kind of thing, it's not well-suited for juggling the binary data used in the bittorrent kademlia implementation. As for your query, `p` is not a valid bencoded DHT request – the8472 Aug 01 '12 at 21:43

1 Answers1

1

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

gsk
  • 558
  • 5
  • 12