package serverP2P;
import serverP2P.ServerManagementUDP;
import serverP2P.ServerManagementTCP;
import tools.Directories;
import tools.Logger;

public class ServerP2P {
	private int port;
	private Directories directories;
	static private final String subdir = "seeded/";
	private Logger logger;


	public ServerP2P() {
		directories = new Directories("P2P_JAVA_PROJECT_SERVER");
		directories.createSubdir(subdir);
		logger = new Logger(directories.getDataHomeDirectory() + "server.log");
		port = 40001;
		System.out.println("Server will listen on port " + port + " and serve files from " + directories.getDataHomeDirectory() + subdir);
		directories.askOpenDataHomeDirectory(subdir);
	}
	public static void main(String [] args) {
		ServerP2P s = new ServerP2P();
		ServerManagementUDP smudp = new ServerManagementUDP(s.directories.getDataHomeDirectory() + subdir, s.port, s.logger);
		ServerManagementTCP smtcp = new ServerManagementTCP(s.directories.getDataHomeDirectory() + subdir, s.port, s.logger);
		Thread tudp = new Thread(smudp);
		tudp.setName("server UDP P2P-JAVA-PROJECT");
		tudp.start();
		Thread ttcp = new Thread(smtcp);
		ttcp.setName("server TCP P2P-JAVA-PROJECT");
		ttcp.start();
	}

}
