pull/1/head
Flavien Haas 5 years ago
parent 71a9b23ce4
commit ecc92f79d1

@ -125,7 +125,7 @@ public class ClientManagementUDP implements Runnable {
* @throws ProtocolError
*/
private void checkProtocolID(String msgProtocolID) throws ProtocolError {
if (protocolID != msgProtocolID) {
if (!protocolID.equals(msgProtocolID)) {
throw new ProtocolError();
}
}
@ -143,8 +143,11 @@ public class ClientManagementUDP implements Runnable {
DatagramPacket reception = new DatagramPacket(buffer, buffer.length);
DatagramPacket emission = new DatagramPacket(buffer, buffer.length, dst, UDPPort);
socket.send(emission);
System.out.print(msg);
socket.receive(reception);
return new String(reception.getData(), 0, reception.getLength());
String tmp = new String(reception.getData(), 0, reception.getLength());
System.out.print(tmp);
return tmp;
} catch (Exception e){
throw new TransmissionError();
}

Binary file not shown.

@ -26,9 +26,10 @@ public class ClientP2P {
} else {
d = ".";
}
d += "P2P_JAVA_PROJECT_CLIENT/";
d += "/P2P_JAVA_PROJECT_CLIENT/";
// create directory if not already exists
new File(d).mkdirs();
directory = d;
}
public static void main(String [] args) {

@ -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

Binary file not shown.

@ -24,9 +24,10 @@ public class ServerP2P {
} else {
d = ".";
}
d += "P2P_JAVA_PROJECT_SERVER/";
d += "/P2P_JAVA_PROJECT_SERVER/";
// create directory if not already exists
new File(d).mkdirs();
directory = d;
}
public static void main(String [] args) {
ServerP2P s = new ServerP2P();

Loading…
Cancel
Save