[bittorrent] getting IP and port from tracker

Philipp Deutscher philipp at postwg.de
Thu May 18 09:39:02 EDT 2006

How can I get the right list of IPs and ports from the tracker? My current
implementation seems to be wrong.
I send the right HTTP get request to the tracker and i get the right tracker
I read the tracker announce via an URLConnection and a DataInputStream and
write the InputStream to a byte array. Than, I convert the
whole byte array to an int array.
I know, that the first part of the tracker announce is a bencoded ASCII
character set and the second part simply consists of
binary data. I convert the binary part in Ip address and port number
consisting of 4 Byte for the Ip and 2 Byte for the port. what's wrong with
The method below begins to work after the last ":" of the ascii part
 public static void convertBinaryPartOfInputArray(int[] a) {
  int i = arrayIndex+1;
  while(i <= a.length-1) {
   userID += 1;
   if(a[i] == 0) {
   System.out.println("IP: "+UsualMethods.ipBuilder(a[i], a[i+1], a[i+2],
   System.out.println("Port: "+UsualMethods.portBuilder(a[i+4], a[i+5]));
    i = i+6;
 } // end of convertBinaryPartOfInputArray
public static String ipBuilder(int one, int two, int three, int four) {
  return Integer.toString(one)+"."+Integer.toString(two)+"."+
 } // end of ipBuilder
public static String portBuilder(int one, int two) {
  return Integer.toString((one << 8) + two);
 } // end of portBuilder
I hope someone can help me out.
Philipp Deutscher
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ibiblio.org/pipermail/bittorrent/attachments/20060518/90e3716a/attachment.html 

More information about the BitTorrent mailing list