Jump to content

P2P File Sharing Application (Java)

Hello everyone,

 

I am currently developing an application to send and receive files.

 

The application announces a list of filenames available by sending UDP datagrams to the broadcast address. All instances of the application must receive this announcements and have an updated list of the files which are in a folder (/shared).

I need to send the files through a tcp connection.

It needs to able to send both small and big files through the socket. The selected file will then go to a /downloads folder

 

I am kinda stuck on the tcp part, appreciate any help

Link to comment
Share on other sites

Link to post
Share on other sites

why reinvent the wheel?  implement a very light http server  (send the files using POST , receive files using GET etc ) or a very basic ftp server (passive or active only) should have plenty of java examples for that.

 

Should also have a look at DC++ works ... this uses a dedicated server software to create "hubs", where p2p clients connect and receive the information about other p2p clients that join or leave the hub (like users on a chat system). The hub server software also handles a basic chat system and handles messages from one p2p client to all p2p clients like search requests - for example p2p client A tells the hub server software he's looking for "madonna" and the hub server software tells each p2p client connected to it that user A asks if they have "madonna" on share, and then only p2p users which have a result with "madonna" reply directly to p2p client A with lists of  search results containing "madonna". 

 

 p2p clients can request file lists from each other directly without the server knowing and can also transfer files from each other.

 

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, mariushm said:

why reinvent the wheel?  implement a very light http server  (send the files using POST , receive files using GET etc ) or a very basic ftp server (passive or active only) should have plenty of java examples for that.

 

Should also have a look at DC++ works ... this uses a dedicated server software to create "hubs", where p2p clients connect and receive the information about other p2p clients that join or leave the hub (like users on a chat system). The hub server software also handles a basic chat system and handles messages from one p2p client to all p2p clients like search requests - for example p2p client A tells the hub server software he's looking for "madonna" and the hub server software tells each p2p client connected to it that user A asks if they have "madonna" on share, and then only p2p users which have a result with "madonna" reply directly to p2p client A with lists of  search results containing "madonna". 

 

 p2p clients can request file lists from each other directly without the server knowing and can also transfer files from each other.

 

It's for a school assigment. It has to be specifically this

 

I'll attack the proposal

It's due to the end of today, i'm in a middle of a coffee frenzy and thinking straight get's though xD

Project-2-proposal.pdf

Link to comment
Share on other sites

Link to post
Share on other sites

When each instance of your application starts, make it listen on a port for connections. You know the IP and port, so you can build an unique ID based on that, like for example a unique 12 character code ... four bytes for  IPv4 address , 2 bytes for the port ... encode that in hexadecimal and you have your 12 character unique ID... example 192.168.0.12 : 8081 becomes C0A8000C1F91

 

You can then broadcast messages to all p2p clients using udp in some custom language you make up

 

C0A8000C1F91 JOIN  = tells all computers you're available to give files

C0A8000C1F91 PING / ALIVE = (optional, project text doesn't say you have to do it) do it every 2-5 minutes so the p2p clients know you're still active. If you don't send that for let's say 20 minutes, other instances of your app may assume you've turned off the app and remove all information about your instance from memory

C0A8000C1F91 QUIT - disconnect, other instances should remove all files that belong to your instance from memory

C0A8000C1F91 ADD [/path/to/filename.extension:filesize] - notify other instances of your application that you can now serve this file (optional : monitor a folder on your hard drive and every time a new file is added there, send this broadcast message)

C0A8000C1F91 DEL [/path/to/filename.extension]

 

that's the broadcast part.

 

You also listen to broadcast messages and ignore yourself but accept from others messages and you can simply have an array of records in memory [ip : port : filename : filesize]  and you could implement some simple commands like

 

CLIENTS - list all clients that broadcast messages (the unique 12 character string for all instances)

FILES C0A8000C1F91  - show files belonging to instance C0A8000C1F91

GET C0A8000C1F91 /path/to/file

 

 

You also  listen on that ip and port, and when you get a request, you reply with the file, just dump it to the other instance.. the other instance should just close the connection once it receives n bytes (since you say the file size when you announce the file)

 

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×