|
|
|
@ -29,8 +29,9 @@ public class ServerP2P {
|
|
|
|
|
* @param portServer binded port
|
|
|
|
|
* @param hostnameTracker tracker hostname
|
|
|
|
|
* @param portTracker tracker port
|
|
|
|
|
* @param isInteractive true if application in interactive mode
|
|
|
|
|
*/
|
|
|
|
|
public ServerP2P(String hostnameServer, int portServer, String hostnameTracker, int portTracker) {
|
|
|
|
|
public ServerP2P(String hostnameServer, int portServer, String hostnameTracker, int portTracker, boolean isInteractive) {
|
|
|
|
|
Scanner scanner = new Scanner(System.in);
|
|
|
|
|
server = new HostItem(hostnameServer, portServer);
|
|
|
|
|
tracker = new HostItem(hostnameTracker, portTracker);
|
|
|
|
@ -38,7 +39,9 @@ public class ServerP2P {
|
|
|
|
|
directories.createSubdir(subdir);
|
|
|
|
|
logger = new Logger(directories.getDataHomeDirectory() + "server.log");
|
|
|
|
|
System.out.println("Server will listen on port " + portServer + " and serve files from " + directories.getDataHomeDirectory() + subdir);
|
|
|
|
|
directories.askOpenDataHomeDirectory(subdir, scanner);
|
|
|
|
|
if(isInteractive){
|
|
|
|
|
directories.askOpenDataHomeDirectory(subdir, scanner);
|
|
|
|
|
}
|
|
|
|
|
scanner.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -56,6 +59,7 @@ public class ServerP2P {
|
|
|
|
|
String hostnameTracker = "";
|
|
|
|
|
int portTracker = 0;
|
|
|
|
|
Scanner scanner = new Scanner(System.in);
|
|
|
|
|
boolean isInteractive = false;
|
|
|
|
|
|
|
|
|
|
if ((args.length != 5) && (args.length != 0)){
|
|
|
|
|
System.out.println("usage : java serveurP2P.ServeurP2P (interactive) or java serveurP2P.ServeurP2P -- <serveurHOSTNAME> <serveurPORT> <trackerHOSTNAME> <trackerPORT> (" + serverPortRange + " and " + trackerPortRange +")");
|
|
|
|
@ -67,6 +71,7 @@ public class ServerP2P {
|
|
|
|
|
hostnameTracker = args[3];
|
|
|
|
|
portTracker = Integer.valueOf(Integer.parseInt(args[4]));
|
|
|
|
|
} else {
|
|
|
|
|
isInteractive = true;
|
|
|
|
|
System.out.println("Server, enter hostname to bind (default = localhost): ");
|
|
|
|
|
hostnameServer = scanner.nextLine();
|
|
|
|
|
if(hostnameServer.equals("")){
|
|
|
|
@ -103,7 +108,7 @@ public class ServerP2P {
|
|
|
|
|
System.out.println("using port : " + portServer);
|
|
|
|
|
System.out.println("tracker hostname : " + hostnameTracker);
|
|
|
|
|
System.out.println("tracker port : " + portTracker);
|
|
|
|
|
ServerP2P s = new ServerP2P(hostnameServer, portServer, hostnameTracker, portTracker);
|
|
|
|
|
ServerP2P s = new ServerP2P(hostnameServer, portServer, hostnameTracker, portTracker, isInteractive);
|
|
|
|
|
ServerManagementUDP smudp = new ServerManagementUDP(s.directories.getDataHomeDirectory() + subdir, s.server, s.tracker, s.logger);
|
|
|
|
|
ServerManagementTCP smtcp = new ServerManagementTCP(s.directories.getDataHomeDirectory() + subdir, s.server, s.tracker, s.logger);
|
|
|
|
|
Thread tudp = new Thread(smudp);
|
|
|
|
|