server doesnt ask to open his home directory when arguments are passed
This commit is contained in:
parent
5e70670cc5
commit
ad41d5aeea
@ -23,6 +23,7 @@ public class ServerP2P {
|
|||||||
private Logger logger;
|
private Logger logger;
|
||||||
private HostItem tracker;
|
private HostItem tracker;
|
||||||
private HostItem server;
|
private HostItem server;
|
||||||
|
private boolean isinteractive;
|
||||||
|
|
||||||
/** Constructor with portServerstr containing a port number.
|
/** Constructor with portServerstr containing a port number.
|
||||||
* @param hostnameServer binded hostname
|
* @param hostnameServer binded hostname
|
||||||
@ -30,7 +31,8 @@ public class ServerP2P {
|
|||||||
* @param hostnameTracker tracker hostname
|
* @param hostnameTracker tracker hostname
|
||||||
* @param portTracker tracker port
|
* @param portTracker tracker port
|
||||||
*/
|
*/
|
||||||
public ServerP2P(String hostnameServer, int portServer, String hostnameTracker, int portTracker) {
|
public ServerP2P(String hostnameServer, int portServer, String hostnameTracker, int portTracker, boolean isinteractive) {
|
||||||
|
this.isinteractive = isinteractive;
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
server = new HostItem(hostnameServer, portServer);
|
server = new HostItem(hostnameServer, portServer);
|
||||||
tracker = new HostItem(hostnameTracker, portTracker);
|
tracker = new HostItem(hostnameTracker, portTracker);
|
||||||
@ -38,7 +40,9 @@ public class ServerP2P {
|
|||||||
directories.createSubdir(subdir);
|
directories.createSubdir(subdir);
|
||||||
logger = new Logger(directories.getDataHomeDirectory() + "server.log");
|
logger = new Logger(directories.getDataHomeDirectory() + "server.log");
|
||||||
System.out.println("Server will listen on port " + portServer + " and serve files from " + directories.getDataHomeDirectory() + subdir);
|
System.out.println("Server will listen on port " + portServer + " and serve files from " + directories.getDataHomeDirectory() + subdir);
|
||||||
|
if(isinteractive){
|
||||||
directories.askOpenDataHomeDirectory(subdir, scanner);
|
directories.askOpenDataHomeDirectory(subdir, scanner);
|
||||||
|
}
|
||||||
scanner.close();
|
scanner.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,6 +60,7 @@ public class ServerP2P {
|
|||||||
String hostnameTracker = "";
|
String hostnameTracker = "";
|
||||||
int portTracker = 0;
|
int portTracker = 0;
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
boolean isinteractive = false;
|
||||||
|
|
||||||
if ((args.length != 5) && (args.length != 0)){
|
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 +")");
|
System.out.println("usage : java serveurP2P.ServeurP2P (interactive) or java serveurP2P.ServeurP2P -- <serveurHOSTNAME> <serveurPORT> <trackerHOSTNAME> <trackerPORT> (" + serverPortRange + " and " + trackerPortRange +")");
|
||||||
@ -67,6 +72,7 @@ public class ServerP2P {
|
|||||||
hostnameTracker = args[3];
|
hostnameTracker = args[3];
|
||||||
portTracker = Integer.valueOf(Integer.parseInt(args[4]));
|
portTracker = Integer.valueOf(Integer.parseInt(args[4]));
|
||||||
} else {
|
} else {
|
||||||
|
isinteractive = true;
|
||||||
System.out.println("Server, enter hostname to bind (default = localhost): ");
|
System.out.println("Server, enter hostname to bind (default = localhost): ");
|
||||||
hostnameServer = scanner.nextLine();
|
hostnameServer = scanner.nextLine();
|
||||||
if(hostnameServer.equals("")){
|
if(hostnameServer.equals("")){
|
||||||
@ -103,7 +109,7 @@ public class ServerP2P {
|
|||||||
System.out.println("using port : " + portServer);
|
System.out.println("using port : " + portServer);
|
||||||
System.out.println("tracker hostname : " + hostnameTracker);
|
System.out.println("tracker hostname : " + hostnameTracker);
|
||||||
System.out.println("tracker port : " + portTracker);
|
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);
|
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);
|
ServerManagementTCP smtcp = new ServerManagementTCP(s.directories.getDataHomeDirectory() + subdir, s.server, s.tracker, s.logger);
|
||||||
Thread tudp = new Thread(smudp);
|
Thread tudp = new Thread(smudp);
|
||||||
|
Loading…
Reference in New Issue
Block a user