title: how to send get request to torrent tracker server
body: <p>I am tying to implement a bit torrent client. I am getting my information from here: <a href="http://wiki.theory.org/BitTorrent_Tracker_Protocol" rel="nofollow">http://wiki.theory.org/BitTorrent_Tracker_Protocol</a>.</p>
  
  <p>I want to send a get request to tracker to get the peer list. Should I set up a udp connection and connect to udp://tracker.thepiratebay.org at port 80? Is this what my request message should look like?</p>
  
  <pre><code>"udp://tracker.thepiratebay.org??info_hash=12345678901234567890
  &amp;peer_id=ABCDEFGHIJKLMNOPQRST
  port=6888
  &amp;downloaded=0
  &amp;left=0
  &amp;event=started "
  </code></pre>
  
  <p>this is my part of my code:</p>
  
  <pre><code>    char *requestToSend;
      int sock;
      struct sockaddr_in servAddr; 
      struct sockaddr_in fromAddr;    
      int fromSize; 
      int respStringLen;
  
      int portNum =80;
      char data_recv[ECHOMAX];
  
      char *hash="12345678901234567890";
      char *id="ABCDEFGHIJKLMNOPQRST";
      char *temp ="udp://tracker.thepiratebay.org??info_hash=12345678901234567890\n&amp;peer_id=ABCDEFGHIJKLMNOPQRST\nport=6888\n&amp;downloaded=0\n&amp;left=0\n&amp;event=started";
      requestToSend = malloc(sizeof(temp)+1);
      sprintf(requestToSend, "%s??info_hash=%s\n&amp;peer_id=%s\nport=%s\n&amp;downloaded=0\n&amp;left=0\n&amp;event=started\0","udp://tracker.thepiratebay.org", hash,id,"6888");
      printf("%s to send \n",  requestToSend);
  
     /* Create a datagram/UDP socket */
      if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) &lt; 0){
          printf("fail create socket");
          return 0;
      }
  
      /* Construct the server address structure */
      struct hostent *hp = gethostbyname("udp://tracker.thepiratebay.org");   
      memset(&amp;servAddr, 0, sizeof(servAddr));    /* Zero out structure */
      servAddr.sin_family = AF_INET;                 /* Internet addr family */
      memcpy( (char *) &amp;servAddr.sin_addr.s_addr, hp-&gt;h_addr, hp-&gt;h_length );
      servAddr.sin_port   = htons(portNum);     /* Server port */
  
  
      //send request to tracker server 
      if (send(sock, requestToSend, strlen(requestToSend), 0) != strlen(requestToSend)){
          printf("fail send");
          return 0;
      }
  
      /* Recv a response */
      fromSize = sizeof(fromAddr);
      if ((respStringLen = recvfrom(sock, data_recv, ECHOMAX, 0, 
           (struct sockaddr *) &amp;fromAddr, &amp;fromSize)) != strlen(requestToSend)){
          printf("fail to recv");
          return 0;
      }
  </code></pre>
  
  <p>this is what I am getting from a torrent file </p>
  
  <pre><code>    dict {
      announce =&gt; str = http://tracker.thepiratebay.org/announce (len = 40)
      announce-list =&gt; list [
          list [
              str = http://tracker.thepiratebay.org/announce (len = 40)
          ]
          list [
              str = udp://tracker.thepiratebay.org:80/announce (len = 42)
          ]
          list [
              str = http://tracker.openbittorrent.com/announce (len = 42)
          ]
          list [
              str = udp://tracker.openbittorrent.com:80/announce (len = 44)
          ]
      ]
      creation date =&gt; int = 1174816388
      encoding =&gt; str = UTF-8 (len = 5)
      info =&gt; dict {
          filehash =&gt; str =
  ¸¥£öüËXþÐS®(äfn6 (len = 20)
          length =&gt; int = 2222949
          name =&gt; str = Audacity.zip (len = 12)
          name.utf-8 =&gt; str = Audacity.zip (len = 12)
          piece length =&gt; int = 32768
          pieces =&gt; str = (null) (len = 0)
      }
  }
  d8:announce40:http://tracker.thepiratebay.org/announce13:announce-listll40:http:                         //tracker.thepiratebay.org/announceel42:udp://tracker.thepiratebay.org:80/announ                         ceel42:http://tracker.openbittorrent.com/announceel44:udp://tracker.openbittorre                         nt.com:80/announceee13:creation datei1174816388e8:encoding5:UTF-84:infod8:fileha                         sh20:
  ¸¥£öüËXþÐS®(äfn66:lengthi2222949e4:name12:Audacity.zip10:name.utf-812:Audacity.z                         yf3-ûBÎNrl lengthi32768e6:pieces1360:þ]úÙÉÅ'NÕæ+gd3fi6è6¶
  </code></pre>