|
|
|
@ -67,13 +67,16 @@ public class ServerManagementUDP implements Runnable {
|
|
|
|
|
* @return data to be send as response
|
|
|
|
|
*/
|
|
|
|
|
String processRequest(String request) {
|
|
|
|
|
System.out.print(request);
|
|
|
|
|
String res = protocolID + "\n";
|
|
|
|
|
String formattedRequest[] = request.split("\n");
|
|
|
|
|
try {
|
|
|
|
|
try {
|
|
|
|
|
checkProtocolID(formattedRequest[0]);
|
|
|
|
|
System.out.print("juste avant le switch");
|
|
|
|
|
switch (formattedRequest[1]) {
|
|
|
|
|
case "LIST":
|
|
|
|
|
System.out.print("liste detectee");
|
|
|
|
|
res += sendFileList();
|
|
|
|
|
break;
|
|
|
|
|
case "DOWNLOAD":
|
|
|
|
@ -99,12 +102,13 @@ public class ServerManagementUDP implements Runnable {
|
|
|
|
|
/** Initialize local list of all files allowed to be shared.
|
|
|
|
|
*/
|
|
|
|
|
private void initFileList() {
|
|
|
|
|
System.out.println(baseDirectory);
|
|
|
|
|
File folder = new File(baseDirectory);
|
|
|
|
|
File[] files = folder.listFiles();
|
|
|
|
|
/* Add non-recursively files's names to fileList */
|
|
|
|
|
for (int i = 0; i < files.length; i++) {
|
|
|
|
|
if (files[i].isFile()) {
|
|
|
|
|
fileList.add(files[i].getName());
|
|
|
|
|
for (File f : files) {
|
|
|
|
|
if (f.isFile()) {
|
|
|
|
|
fileList.add(f.getName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -115,7 +119,8 @@ public class ServerManagementUDP implements Runnable {
|
|
|
|
|
* @throws ProtocolError
|
|
|
|
|
*/
|
|
|
|
|
private void checkProtocolID(String msgProtocolID) throws ProtocolError {
|
|
|
|
|
if (protocolID != msgProtocolID) {
|
|
|
|
|
System.out.print(msgProtocolID + "\n" + protocolID);
|
|
|
|
|
if (!protocolID.equals(msgProtocolID)) {
|
|
|
|
|
throw new ProtocolError();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -146,9 +151,9 @@ public class ServerManagementUDP implements Runnable {
|
|
|
|
|
private String sendFileList() {
|
|
|
|
|
String res = "LIST\n";
|
|
|
|
|
for (String f : fileList) {
|
|
|
|
|
res += (f + '\n');
|
|
|
|
|
res += (f + "\n");
|
|
|
|
|
}
|
|
|
|
|
return res + '\n';
|
|
|
|
|
return res + "\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Prepare data to be send if protocol error is detected
|
|
|
|
|