2020-01-14 11:10:11 +01:00
|
|
|
package clientP2P;
|
|
|
|
import java.io.File;
|
|
|
|
import clientP2P.ClientManagementUDP;
|
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;
|
|
|
|
private String directory;
|
2020-01-14 11:10:11 +01:00
|
|
|
public ClientP2P() {
|
2020-01-12 23:29:49 +01:00
|
|
|
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");
|
2020-01-14 11:10:11 +01:00
|
|
|
if (d == null || d.equals("")) {
|
2020-01-12 23:29:49 +01:00
|
|
|
d = System.getenv().get("HOME");
|
2020-01-14 11:10:11 +01:00
|
|
|
if (d != null && (!d.equals(""))) {
|
2020-01-12 23:29:49 +01:00
|
|
|
d += "/.local/share";
|
|
|
|
} else {
|
2020-01-14 11:10:11 +01:00
|
|
|
d += ".";
|
2020-01-12 23:29:49 +01:00
|
|
|
}
|
|
|
|
}
|
2020-01-15 21:58:11 +01:00
|
|
|
} 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 {
|
2020-01-12 23:29:49 +01:00
|
|
|
d = ".";
|
|
|
|
}
|
2020-01-14 11:55:02 +01:00
|
|
|
d += "/P2P_JAVA_PROJECT_CLIENT/";
|
2020-01-12 23:29:49 +01:00
|
|
|
// create directory if not already exists
|
|
|
|
new File(d).mkdirs();
|
2020-01-14 11:55:02 +01:00
|
|
|
directory = d;
|
2020-01-14 12:33:21 +01:00
|
|
|
System.out.println("Client will try to contact server at " + host + " on port " + port + ". It will save files in " + directory);
|
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-01-12 23:29:49 +01:00
|
|
|
ClientManagementUDP cm = new ClientManagementUDP(c.directory, c.host, c.port);
|
|
|
|
Thread t = new Thread(cm);
|
|
|
|
t.setName("client P2P-JAVA-PROJECT");
|
|
|
|
t.start();
|
2019-12-12 11:57:02 +01:00
|
|
|
}
|
|
|
|
}
|