0
I Use This!
Activity Not Available

Project Summary

import java.io.;

import java.net.;

import java.util.;

public class BTclient

{

private TorrentFileHandler torrent_file_handler;
public TorrentFile torrent_file;
//bencoder = new Bencoder();
public BTclient(){
super();
BTclientOpenFile();
}
public void BTclientOpenFile() {

//unencodes the data and extracts the fields necessary for the first project.

torrent_file_handler = new TorrentFileHandler();
torrent_file = torrent_file_handler.openTorrentFile("Rutgers_Fight_Song.mp3.torrent");
//open torrent file
}
public void BTclientShowFile() {
if (torrent_file != null) {
System.out.println("Torrent Information");
System.out.println();
System.out.println("Tracker URL: " + torrent_file.tracker_url);
System.out.println("File Size (Bytes): " + torrent_file.file_length);
System.out.println("Piece Size (Bytes): "+ torrent_file.piece_length);
System.out.println("SHA-1 Info Hash: " + torrent_file.info_hash_as_url);

for (int i = 0; i < torrent_file.piece_hash_values_as_hex.size(); i++)
{
System.out.println("SHA-1 Hash for Piece ["
+ i
+ "]: "
+ (String) torrent_file.piece_hash_values_as_url
.elementAt(i));
}
}
else
{
System.err.println("Error: There was a problem when unencoding the file \"Rutgers_Fight_Song.mp3.torrent\".");
System.err.println("\t\tPerhaps it does not exist.");
}
}
public String BTclientParseUrl() {

String req = torrent_file.tracker_url;
System.out.println(req);
int index1, index2;
index1 = req.indexOf('/',1);
index1 = req.indexOf('/',index1+1);
if (index1 != -1) {
index2 = req.indexOf('/',index1+1);
if (index2 > index1) {
return req.substring(index1+1, index2);
}
}
return null;
}
public void BTclientToTracker() {
Socket sock = null; // Socket object for communicating
PrintWriter out = null; // socket output to server
BufferedReader in = null; // socket input from server

//String tracker_url = torrent_file.tracker_url;
String info_hash = torrent_file.info_hash_as_url;

try {
sock = new Socket("rigatoni.rutgers.edu",6881); // create socket and connect
out = new PrintWriter(sock.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
System.out.println();
System.out.println("BitTorrent Client");
System.out.println(" -> connected to Server");
out.println("GET"+"&torrent_file.tracker_url"+"?"+"info_hash="+"&torrent_file.info_hash_as_url"+
"&HTTP/1.0"+"\r\n");

boolean loop = true;
System.out.println(" -> sent message to server");

StringBuffer sb = new StringBuffer(8096);

System.out.println(" -> waiting server");
while (loop) {
if (in.ready()) {
int i=0;
while (i != -1) {
i = in.read();
sb.append((char) i);
}
loop = false;
System.out.println(" ->received message from server");
System.out.println("----------------------------------");
}
}

System.out.println(sb.toString());
System.out.println("----------------------------------");
System.out.println(" -> end of message");
sock.close();
System.out.println(" -> leavin.");
}
catch (Throwable e) {
System.out.println("Error " + e.getMessage());
e.printStackTrace();
}
}
public static void main(String args) {
BTclient bc = new BTclient();

System.out.println(bc.BTclientParseUrl());
bc.BTclientShowFile();
bc.BTclientToTracker();
//BencoderTester bt = new BencoderTester();
}
}

Tags

benocoding bittorrent java

In a Nutshell, project01-...

 No code available to analyze

Open Hub computes statistics on FOSS projects by examining source code and commit history in source code management systems. This project has no code locations, and so Open Hub cannot perform this analysis

Is this project's source code hosted in a publicly available repository? Do you know the URL? If you do, click the button below and tell us so that Open Hub can generate statistics! It's fast and easy - try it and see!

Add a code location

GNU General Public License v2.0 or later
Permitted

Commercial Use

Modify

Distribute

Place Warranty

Forbidden

Sub-License

Hold Liable

Required

Distribute Original

Disclose Source

Include Copyright

State Changes

Include License

These details are provided for information only. No information here is legal advice and should not be used as such.

All Licenses

This Project has No vulnerabilities Reported Against it

Did You Know...

  • ...
    Black Duck offers a free trial so you can discover if there are open source vulnerabilities in your code
  • ...
    you can embed statistics from Open Hub on your site
  • ...
    use of OSS increased in 65% of companies in 2016
  • ...
    you can subscribe to e-mail newsletters to receive update from the Open Hub blog

 No code available to analyze

Open Hub computes statistics on FOSS projects by examining source code and commit history in source code management systems. This project has no code locations, and so Open Hub cannot perform this analysis

Is this project's source code hosted in a publicly available repository? Do you know the URL? If you do, click the button below and tell us so that Open Hub can generate statistics! It's fast and easy - try it and see!

Add a code location

Community Rating

Be the first to rate this project
Click to add your rating
   Spinner
Review this Project!
Sample ohloh analysis