Bittorrent program


 
Thread Tools Search this Thread
Top Forums Programming Bittorrent program
# 1  
Old 03-31-2010
Bittorrent program

Hi everyone,
I'm trying to replicate a bittorrent program using Linux client/server programming. I have a few questions on how to approach this..

1) If I write a client/server program, can it be merged together? Usually bittorrent programs can send/receive files

2) Doing it step by step, I would like to send a file from the server to the client. Problem is, how can I find out the name of the file that I am trying to send from the server to the client? For example, image.jpg.

3) I've tried sending a flat file over, say textfile.txt, but on the client side it appends some junk character at the end of it. What causes the characters to appear?

That's the questions I have for now. Will post more if it comes up. Thanks!

---------- Post updated at 12:35 PM ---------- Previous update was at 11:28 AM ----------

Hmm I fixed the junk character appending, but somehow it only works when sending txt files from client to server. Sending any image files, results in a smaller, corrupted file for some reason.

Client code:

Code:
while ( (n = read(sock, buffer, sizeof(buffer))) > 0)
{
           fprintf(fw,buffer);
}

In the client side, sock is the socket, while fw is the file to write to (eg: image.gif)

Server code:

Code:
while (( n = read(fw,buffer2, sizeof(buffer2)))> 0 )
{
            write(fd, buffer2,sizeof(buffer2));
}

In the server, fw is the file to read from (eg: image.gif), and fd is the socket to write to.

Any help greatly appreciated =)

Last edited by Shiroi98; 03-31-2010 at 03:40 PM..
# 2  
Old 04-01-2010
You need to send the file size before sending actual file. Because this is binary data, you MUST NOT treat this as string data.

Also while reading/writing you should check how bytes has been actually read/written. Based on this you should move your read/write point. e.g. while writing it should be
Code:
while (( n = read(fw,buffer2, sizeof(buffer2)))> 0 )
{
            write(fd, buffer2,n));  // use n here instead of sizeof(buffer2)
}

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automating BitTorrent traffic detection via bash

Hi all, Earlier today, I read an article on how to detect BitTorrent traffic using tshark (the cli version of Wireshark). I wanted to have a go at creating a simple script, that when BitTorrent packets are detected the network connection will be throttled. The thing is that I am not great at... (1 Reply)
Discussion started by: ShrewNet
1 Replies

2. Shell Programming and Scripting

Perl program get a response before the program quits

I created a program, so a kid can practice there math on it. It dispenses varies math problems and the kid must input an answer. I also want it to grade the work they have done, but I can't find the best place for it to print out the grade. I have: if ( $response =~ m/^/ ) { $user_wants_to_quit... (1 Reply)
Discussion started by: germany1517
1 Replies

3. Homework & Coursework Questions

Calling compiled C program with Perl program

Long story short: I'm working inside of a Unix SSH under a bash shell. I have to code a C program that generates a random number. Then I have to call the compiled C program with a Perl program to run the C program 20 times and put all the generated random #s into a text file, then print that text... (1 Reply)
Discussion started by: jdkirby
1 Replies

4. Programming

Python program faster than C++ program.

I wrote a simple program that generates a random word 10,000,000 times. I wrote it in python, then in C++ and compared the two completion times. The python script was faster! Is that normal? Why would the python script be faster? I was under the impression that C++ was faster. What are some of... (2 Replies)
Discussion started by: cbreiny
2 Replies

5. IP Networking

Unknown open port: "6881/tcp open bittorrent-tracker" found with nmap

Hi. I ran nmap on my server, and I get the following: Starting Nmap 4.76 ( http://nmap.org ) at 2009-03-19 16:33 EDT Interesting ports on -------- (-----): Not shown: 997 closed ports PORT STATE SERVICE 22/tcp open ssh 80/tcp open http 6881/tcp open bittorrent-tracker The... (0 Replies)
Discussion started by: Rledley
0 Replies

6. UNIX for Dummies Questions & Answers

Script to open program and send/execute command in program

Hi, i want to write a script that executes a program (exec?) . this program then requires a filename as input. how do i give it this input in the script so the program will be complete run and close by the script. e.g. exec prog.exe program then asks for filename "enter filename:"... (1 Reply)
Discussion started by: tuathan
1 Replies

7. UNIX for Dummies Questions & Answers

Bittorrent over SSH

Hi, I'm behind a university firewall where nearly all ports are blocked. Therefore I've set up a ssh tunnel to my comp at home so that I can bypass the uni firewall and use bittorrent. I used mainly these 3 guides to setup the tunnel: http://freebsdcluster.org/~lasse/sshazureustunnel/ , Whalesalad... (1 Reply)
Discussion started by: bizso
1 Replies

8. IP Networking

BitTorrent port 6969 blocked... how to get around the blocked port

Due to the massive Upload speeds killing .... or overstressing our schools network...... my school has blocked port 6969 (the most common BitTorrent port). So I cant connect to the tracker anymore, in other words no more downloading from school :( Does anyone know how I can get around the ports... (1 Reply)
Discussion started by: PenguinDevil
1 Replies
Login or Register to Ask a Question