@ -3,6 +3,7 @@ import serverP2P.ServerManagementUDP;
import serverP2P.ServerManagementTCP ;
import tools.Directories ;
import tools.Logger ;
import tools.HostItem ;
/ * * Server only implementation
* First argument of main method is port listened by the server , and is mandatory .
@ -16,12 +17,14 @@ public class ServerP2P {
private Directories directories ;
static private final String subdir = "seeded/" ;
private Logger logger ;
private HostItem tracker ;
/ * * Constructor with portStr containing a port number .
* @param portStr String containing port number of listening .
* /
public ServerP2P ( String portStr ) {
public ServerP2P ( String portStr , String trackerHostname , String trackerPortStr ) {
port = Integer . valueOf ( Integer . parseInt ( portStr ) ) ;
tracker = new HostItem ( trackerHostname , Integer . valueOf ( Integer . parseInt ( trackerPortStr ) ) ) ;
directories = new Directories ( "P2P_JAVA_PROJECT_SERVER_" + port ) ;
directories . createSubdir ( subdir ) ;
logger = new Logger ( directories . getDataHomeDirectory ( ) + "server.log" ) ;
@ -31,18 +34,17 @@ public class ServerP2P {
/ * * Main program entry point
* first parameter is port number and is mandatory
* to test , run with : java - ea serverP2P . ServerP2P - - < portNumber >
* to test , run with : java - ea serverP2P . ServerP2P - - < portNumber > < TrackerHostname > < TrackerPort >
* @param args parameters
* /
public static void main ( String [ ] args ) {
if ( args [ 1 ] . equals ( "help" ) | | args [ 1 ] . equals ( "-h" ) | | args [ 1 ] . equals ( "h" ) ) {
System . out . println ( "usage : java -ea serveurP2P.ServeurP2P -- <serveurPORT> <trackerHOSTNAME> <trackerPORT>" ) ;
}
else {
ServerP2P s = new ServerP2P ( args [ 1 ] );
ServerManagementUDP smudp = new ServerManagementUDP ( s . directories . getDataHomeDirectory ( ) + subdir , s . port , s . logger );
ServerManagementTCP smtcp = new ServerManagementTCP ( s . directories . getDataHomeDirectory ( ) + subdir , s . port , s . logger );
ServerP2P s = new ServerP2P ( args [ 1 ] , args [ 2 ] , args [ 3 ] );
ServerManagementUDP smudp = new ServerManagementUDP ( s . directories . getDataHomeDirectory ( ) + subdir , s . port , s . logger , s . tracker );
ServerManagementTCP smtcp = new ServerManagementTCP ( s . directories . getDataHomeDirectory ( ) + subdir , s . port , s . logger , s . tracker );
Thread tudp = new Thread ( smudp ) ;
tudp . setName ( "server UDP P2P-JAVA-PROJECT" ) ;
tudp . start ( ) ;