java - Getting scrambled replies from DHT bootsraps for Bittorrent -


i'm trying implement dht node in bittorrent mainline. far got connection in , out against bootstrap node, query seems fine according bencoded examples part of result i'm getting scrambled (the parts containing actual data):

d2:ip6:µ§ û©Å1:rd2:id20:ëÿ6isqÿjì)ͺ«òûãf|Âge1:t2:aa1:y1:re 

this code far:

private static string servername = "router.utorrent.com"; private static int port = 6881; private static string packet = "d1:ad2:id20:abcdefghij0123456789e1:q4:ping1:t2:aa1:y1:qe"; public static void main(string[] args)  {      int port = main.port;     inetaddress address = inetaddress.getbyname(main.servername);     datagramsocket socket = new datagramsocket();      byte[] buf = main.packet.getbytes();     datagrampacket packet = new datagrampacket(buf, buf.length, address, port);     socket.send(packet);     byte[] recbuf = new byte[2048];     datagrampacket recpacket = new datagrampacket(recbuf, recbuf.length);      socket.receive(recpacket);      system.out.println(new string(extract(recpacket))); }    private static byte[] extract(datagrampacket packet) {         byte[] data = packet.getdata();         int offset = packet.getoffset();         int length = packet.getlength();          byte[] copy = new byte[length];         system.arraycopy(data, offset, copy, 0, copy.length);          return copy;       } 

i'm not sure whether have chartset problem or there encoding couldn't find specified anywhere.

your response looks correct me. sounds expect dht protocol use ascii characters, doesn't. 160 bit node id transferred 20 bytes , ip , port transferred 6 bytes.

see protocol specification.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -