package clientP2P; import clientP2P.ClientManagementUDP; import clientP2P.ClientManagementTCP; import tools.Directories; import java.util.Scanner; import java.util.List; import tools.HostItem; import tools.HostList; public class ClientP2P { private String host; private int port; private Directories directories; private List hostList; private String parts = ".parts"; public ClientP2P() { directories = new Directories("P2P_JAVA_PROJECT_CLIENT"); directories.createSubdir(parts); 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); System.out.println("Please enter list of servers to use; first one will be used to ask list of files"); hostList = HostList.getServList(); } 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 "upd": // alias typo case "2" : System.out.println("Starting with UDP"); ClientManagementUDP cmudp = new ClientManagementUDP(c.directories.getDataHomeDirectory(), c.hostList, c.directories.getDataHomeDirectory() + c.parts + "/"); 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.hostList, c.directories.getDataHomeDirectory() + c.parts + "/"); t = new Thread(cmtcp); break; } t.setName("client P2P-JAVA-PROJECT"); t.start(); } }