package clientP2P; import java.io.File; import clientP2P.ClientManagementUDP; public class ClientP2P { private String host; private int port; private String directory; public ClientP2P() { host = "localhost"; port = 40000; String d; /* Follow XDG Base Directory Specification * https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html */ if (System.getProperty("os.name").equals("Linux")) { d = System.getenv().get("XDG_DATA_HOME"); if (d == null || d.equals("")) { d = System.getenv().get("HOME"); if (d != null && (!d.equals(""))) { d += "/.local/share"; } else { d += "."; } } } else if (os.equals("Mac")||os.equals("Mac OS X") { /* Apple MacOS X User Data Directory * https://developer.apple.com/library/archive/qa/qa1170/_index.html */ d = System.getProperty("user.home") + "/Library"; } else { d = "."; } d += "/P2P_JAVA_PROJECT_CLIENT/"; // create directory if not already exists new File(d).mkdirs(); directory = d; System.out.println("Client will try to contact server at " + host + " on port " + port + ". It will save files in " + directory); } public static void main(String [] args) { ClientP2P c = new ClientP2P(); ClientManagementUDP cm = new ClientManagementUDP(c.directory, c.host, c.port); Thread t = new Thread(cm); t.setName("client P2P-JAVA-PROJECT"); t.start(); } }