multiple servers impl (does not work yet)

pull/23/head
js 5 years ago committed by Louis
parent 78deb16e41
commit 9fa68b9e98

@ -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();
}

@ -17,7 +17,7 @@ public class HostList{
/**
* Let the user enter all server and puts it in a list
* @return list of servers
* @return list of servers
*/
public List<String> getServList(){
@ -25,7 +25,7 @@ public class HostList{
Scanner scanner = new Scanner(System.in);
String servName = "";
do {
System.out.println("Name of the next server:");
System.out.println("Name of the next server: (or \"stop\" when finished)");
servName = scanner.nextLine();
if (servName != "stop"){
serverList.add(servName);

Loading…
Cancel
Save