Question
I need to build a Napster-based Centralized Peer-to-Peer File Sharing Application using Socket and Multi-thread Programming. The application will be designed as a hybrid version
I need to build a Napster-based Centralized Peer-to-Peer File Sharing Application using Socket and Multi-thread Programming. The application will be designed as a hybrid version of client-server and P2P programming models and by using threads.
Centralized Multi-threaded Directory Server:
A centralized server will listen on a certain port for incoming connection requests from peers. It will create a separate thread and a socket for each thread and the connection will be active as long as peers are online. The server will provide the following functionalities to the peers:
Register peers:
The directory server will listen to a TCP socket at a well-known port. A new client peer will contact the directory server at this port and indicate its presence. In addition, the directory server also listens to a UDP socket and every 60 seconds the client peer issues a 'HELLO' message to the UDP port of the registry. If the directory server has not received a HELLO message from a client peer in 200 seconds, the client is removed from the list of available clients. After registration, the client sends a list of files available at the client to the directory server.
Search files:
Peers will make a search request for a certain file they are looking for to the directory server. The directory server will search on its data structures and return a list of peers (along with their IPs) that have the file requested to the requesting peer.
Update peer/file list:
When a download takes place, the downloading peer informs the server that it has a new file added to its shared folder and the server will make a change in the file list of the peer. When a peer is offline, the server deletes all information regarding the peer from its data structures.
Peer:
Peer can interact with the directory server and other peers. It registers itself with the directory server by providing its IP and file list that it wants to share. The peer can search for a certain file and when the server responds with the list of peers who have the file, the peer selects one of the peers and makes a connection request to the peer to download the file. Do not forget while onedownload is in progress, the peer client may have other search requests and download operations. The peer should have a GUI to connect, search for files, list peers and monitor download activity. At the same time, the peer is also a server. When a peer registers with the centralized server, it also launches a peer server to serve download requests coming from other peers. The peer server will be multi-threaded and will be able to serve more than one peer at the same time. It will listen for incoming connections and send requested files.
Side note: Any updates to the shared data structures by the threads should be synchronized. All communication will be across TCP sockets except the HELLO messages which are UDP datagrams. The registry has to listen to a well-known ports for registration of new clients and for file queries. Each client also listens for requests for file transfers on a TCP socket
If you could comment the code so I know how it works I am trying to figure out how to do this myself as well, Thank you
This is what I have so far:
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */
package PeerClient;
/** * * @author */ public class PeerServer { }
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */
package DirectoryServer;
/** * * @author Justin */ public class DirectoryThread extends Thread { @Override public void run() { } }
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */
package DirectoryServer;
import java.io.IOException; import java.net.DatagramSocket; import java.net.ServerSocket;
/** * * @author Justin */ public class DirectoryServer { public static void main(String[] args) throws IOException { int port;
try { port = Integer.parseInt(args[0]);
try { ServerSocket tcpSocket = new ServerSocket(port); DatagramSocket udpSocket = new DatagramSocket(port); System.out.println("Directory Server Started on port: " + port);
while (true) { new DirectoryThread().start(); }
} catch (IOException e) { System.err.println("Could not listen on port: " + args[0]); System.err.println(e.getMessage()); System.exit(-1); } } catch (NumberFormatException e) { System.out.println("Please supply a valid port number"); } } }
and A PeerClient Class for searching
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started