package clientP2P;
import clientP2P.ClientManagementUDP;
import clientP2P.ClientManagementTCP;
import tools.Directories;
import java.util.Scanner;

public class ClientP2P {
	private String host;
	private int port;
	private Directories directories;
	public ClientP2P() {
		directories = new Directories("P2P_JAVA_PROJECT_CLIENT");
		host = "localhost";
		port = 40001;
		System.out.println("Client will try to contact server at " + host + " on port " + port + ". It will save files in " + directories.getDataHomeDirectory());
		directories.askOpenDataHomeDirectory(null);
	}

	public static void main(String [] args) {
		ClientP2P c = new ClientP2P();
		System.out.println("Which transport protocol do you want to use? [TCP/udp]");
		Scanner sc = new Scanner(System.in);
		String transportchoosen = sc.nextLine();
		Thread t;
		switch(transportchoosen){
			case "UDP":
			case "udp":
			case "2" :
				System.out.println("Starting with UDP");
				ClientManagementUDP cmudp = new ClientManagementUDP(c.directories.getDataHomeDirectory(), c.host, c.port);
				t = new Thread(cmudp);
				break;
			case "TCP":
			case "tcp":
			case "1":
			default:
				System.out.println("Starting with TCP");
				ClientManagementTCP cmtcp = new ClientManagementTCP(c.directories.getDataHomeDirectory(), c.host, c.port);
				t = new Thread(cmtcp);
				break;
		  }

		t.setName("client P2P-JAVA-PROJECT");
		t.start();
	}
}
