private void generateTrackerURL() throws IOException {
	  //String buffer we'll store the url extension in. Initialized to base URL.
	  StringBuffer urlExtension = new StringBuffer( (torrentInfo.announce_url).toString() );
	  
	  //Generate the info_hash parameter and add to URL.
	  urlExtension.append("?info_hash=");
	  for (byte b : torrentInfo.info_hash.array()) {  
	    urlExtension.append("%");
	    urlExtension.append(String.format("%02X", b));   
	  } 

	  //Add peerID parameter to URL.
	  urlExtension.append("&peer_id=");
	  for (byte b: peerID){
	    urlExtension.append("%");
	    urlExtension.append(String.format("%02X", b));
	  }
	  
	  //Wait for the SocketListener to find a free port 
	  while(manager.getListeningPort() == 0)
	  {
		  try {
			  Thread.sleep(1000L);
		  }
		  catch (InterruptedException e) { }
	  }
	  this.port = manager.getListeningPort();
	  //Add port parameter to URL.
	  urlExtension.append("&port=");
	  urlExtension.append( port );

	  //Add uploaded parameter to URL.
	  urlExtension.append("&uploaded=");
	  urlExtension.append( uploaded );

	  //Add downloaded parameter to URL.
	  urlExtension.append("&downloaded=");
	  urlExtension.append( downloaded );
	  
	  //Add left parameter to URL.
	  urlExtension.append("&left=");
	  urlExtension.append( left );

	  //Add event parameter to URL.
	  if(this.event != null){
		  urlExtension.append("&event=");
		  for (byte b: event){
			  urlExtension.append("%");
			  urlExtension.append(String.format("%02X", b));
		  }
	  }

	  //Finally, set value.
	  this.trackerURL = new URL(urlExtension.toString());
	}