|
|
|
@ -1,16 +1,25 @@
|
|
|
|
|
package clientP2P;
|
|
|
|
|
import clientP2P.ClientManagementUDP;
|
|
|
|
|
import clientP2P.ClientManagementTCP;
|
|
|
|
|
import tools.HostList;
|
|
|
|
|
import tools.Directories;
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.ListIterator;
|
|
|
|
|
|
|
|
|
|
public class ClientP2P {
|
|
|
|
|
private String host;
|
|
|
|
|
private int port;
|
|
|
|
|
private Directories directories;
|
|
|
|
|
private List<String> hostList;
|
|
|
|
|
private HostList tool = new HostList();
|
|
|
|
|
|
|
|
|
|
public ClientP2P() {
|
|
|
|
|
directories = new Directories("P2P_JAVA_PROJECT_CLIENT");
|
|
|
|
|
host = "localhost";
|
|
|
|
|
hostList = tool.getServList();
|
|
|
|
|
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);
|
|
|
|
@ -27,8 +36,18 @@ public class ClientP2P {
|
|
|
|
|
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);
|
|
|
|
|
/* ListIterator<String> it = c.hostList.listIterator();
|
|
|
|
|
do {
|
|
|
|
|
String str = it.next();
|
|
|
|
|
ClientManagementUDP cmudp = new ClientManagementUDP(c.directories.getDataHomeDirectory(), str, c.port);
|
|
|
|
|
t = new Thread(cmudp);
|
|
|
|
|
} while (it.hasNext());
|
|
|
|
|
*/
|
|
|
|
|
for (String str : c.hostList){
|
|
|
|
|
ClientManagementUDP cmudp = new ClientManagementUDP(c.directories.getDataHomeDirectory(), str, c.port);
|
|
|
|
|
t = new Thread(cmudp);
|
|
|
|
|
}
|
|
|
|
|
//ClientManagementUDP cmudp = new ClientManagementUDP(c.directories.getDataHomeDirectory(), c.host, c.port);
|
|
|
|
|
break;
|
|
|
|
|
case "TCP":
|
|
|
|
|
case "tcp":
|
|
|
|
@ -39,7 +58,6 @@ public class ClientP2P {
|
|
|
|
|
t = new Thread(cmtcp);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t.setName("client P2P-JAVA-PROJECT");
|
|
|
|
|
t.start();
|
|
|
|
|
}
|
|
|
|
|