2020-01-14 11:10:11 +01:00
|
|
|
package clientP2P;
|
|
|
|
import clientP2P.ClientManagementUDP;
|
2020-02-29 16:57:19 +01:00
|
|
|
import clientP2P.ClientManagementTCP;
|
2020-01-16 12:35:06 +01:00
|
|
|
import tools.Directories;
|
2020-02-03 14:48:56 +01:00
|
|
|
import java.util.Scanner;
|
2020-03-11 20:19:18 +01:00
|
|
|
import java.util.List;
|
|
|
|
import tools.HostItem;
|
|
|
|
import tools.HostList;
|
2019-12-12 11:57:02 +01:00
|
|
|
|
2020-01-14 11:10:11 +01:00
|
|
|
public class ClientP2P {
|
2020-01-12 23:29:49 +01:00
|
|
|
private String host;
|
|
|
|
private int port;
|
2020-01-21 19:56:50 +01:00
|
|
|
private Directories directories;
|
2020-03-11 20:19:18 +01:00
|
|
|
private List<HostItem> hostList;
|
|
|
|
private String parts = ".parts";
|
2020-01-14 11:10:11 +01:00
|
|
|
public ClientP2P() {
|
2020-01-21 19:56:50 +01:00
|
|
|
directories = new Directories("P2P_JAVA_PROJECT_CLIENT");
|
2020-03-11 20:19:18 +01:00
|
|
|
directories.createSubdir(parts);
|
2020-01-12 23:29:49 +01:00
|
|
|
host = "localhost";
|
2020-01-25 17:48:21 +01:00
|
|
|
port = 40001;
|
2020-01-21 19:48:46 +01:00
|
|
|
System.out.println("Client will try to contact server at " + host + " on port " + port + ". It will save files in " + directories.getDataHomeDirectory());
|
2020-03-03 19:30:04 +01:00
|
|
|
directories.askOpenDataHomeDirectory(null);
|
2020-03-11 20:19:18 +01:00
|
|
|
System.out.println("Please enter list of servers to use; first one will be used to ask list of files");
|
|
|
|
hostList = HostList.getServList();
|
2020-01-12 23:29:49 +01:00
|
|
|
}
|
2020-01-14 11:10:11 +01:00
|
|
|
|
2019-12-12 11:57:02 +01:00
|
|
|
public static void main(String [] args) {
|
2020-01-14 11:10:11 +01:00
|
|
|
ClientP2P c = new ClientP2P();
|
2020-02-03 14:48:56 +01:00
|
|
|
System.out.println("Which transport protocol do you want to use? [TCP/udp]");
|
|
|
|
Scanner sc = new Scanner(System.in);
|
|
|
|
String transportchoosen = sc.nextLine();
|
2020-02-29 00:19:50 +01:00
|
|
|
Thread t;
|
2020-02-03 14:48:56 +01:00
|
|
|
switch(transportchoosen){
|
|
|
|
case "UDP":
|
|
|
|
case "udp":
|
|
|
|
case "2" :
|
2020-02-29 16:57:19 +01:00
|
|
|
System.out.println("Starting with UDP");
|
2020-03-12 17:52:31 +01:00
|
|
|
ClientManagementUDP cmudp = new ClientManagementUDP(c.directories.getDataHomeDirectory(), c.hostList, c.directories.getDataHomeDirectory() + c.parts + "/");
|
2020-02-29 00:19:50 +01:00
|
|
|
t = new Thread(cmudp);
|
2020-02-03 14:48:56 +01:00
|
|
|
break;
|
|
|
|
case "TCP":
|
|
|
|
case "tcp":
|
|
|
|
case "1":
|
|
|
|
default:
|
2020-02-29 16:57:19 +01:00
|
|
|
System.out.println("Starting with TCP");
|
2020-03-11 20:19:18 +01:00
|
|
|
ClientManagementTCP cmtcp = new ClientManagementTCP(c.directories.getDataHomeDirectory(), c.hostList);
|
2020-02-29 16:57:19 +01:00
|
|
|
t = new Thread(cmtcp);
|
|
|
|
break;
|
2020-02-03 14:48:56 +01:00
|
|
|
}
|
2020-02-29 00:19:50 +01:00
|
|
|
|
2020-01-12 23:29:49 +01:00
|
|
|
t.setName("client P2P-JAVA-PROJECT");
|
|
|
|
t.start();
|
2019-12-12 11:57:02 +01:00
|
|
|
}
|
|
|
|
}
|