erreurs
This commit is contained in:
parent
71a9b23ce4
commit
ecc92f79d1
1
src/P2P_JAVA_PROJECT_SERVER/bonjour
Normal file
1
src/P2P_JAVA_PROJECT_SERVER/bonjour
Normal file
@ -0,0 +1 @@
|
|||||||
|
bonjour
|
Binary file not shown.
@ -125,7 +125,7 @@ public class ClientManagementUDP implements Runnable {
|
|||||||
* @throws ProtocolError
|
* @throws ProtocolError
|
||||||
*/
|
*/
|
||||||
private void checkProtocolID(String msgProtocolID) throws ProtocolError {
|
private void checkProtocolID(String msgProtocolID) throws ProtocolError {
|
||||||
if (protocolID != msgProtocolID) {
|
if (!protocolID.equals(msgProtocolID)) {
|
||||||
throw new ProtocolError();
|
throw new ProtocolError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,8 +143,11 @@ public class ClientManagementUDP implements Runnable {
|
|||||||
DatagramPacket reception = new DatagramPacket(buffer, buffer.length);
|
DatagramPacket reception = new DatagramPacket(buffer, buffer.length);
|
||||||
DatagramPacket emission = new DatagramPacket(buffer, buffer.length, dst, UDPPort);
|
DatagramPacket emission = new DatagramPacket(buffer, buffer.length, dst, UDPPort);
|
||||||
socket.send(emission);
|
socket.send(emission);
|
||||||
|
System.out.print(msg);
|
||||||
socket.receive(reception);
|
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){
|
} catch (Exception e){
|
||||||
throw new TransmissionError();
|
throw new TransmissionError();
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -26,9 +26,10 @@ public class ClientP2P {
|
|||||||
} else {
|
} else {
|
||||||
d = ".";
|
d = ".";
|
||||||
}
|
}
|
||||||
d += "P2P_JAVA_PROJECT_CLIENT/";
|
d += "/P2P_JAVA_PROJECT_CLIENT/";
|
||||||
// create directory if not already exists
|
// create directory if not already exists
|
||||||
new File(d).mkdirs();
|
new File(d).mkdirs();
|
||||||
|
directory = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String [] args) {
|
public static void main(String [] args) {
|
||||||
|
Binary file not shown.
@ -67,13 +67,16 @@ public class ServerManagementUDP implements Runnable {
|
|||||||
* @return data to be send as response
|
* @return data to be send as response
|
||||||
*/
|
*/
|
||||||
String processRequest(String request) {
|
String processRequest(String request) {
|
||||||
|
System.out.print(request);
|
||||||
String res = protocolID + "\n";
|
String res = protocolID + "\n";
|
||||||
String formattedRequest[] = request.split("\n");
|
String formattedRequest[] = request.split("\n");
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
checkProtocolID(formattedRequest[0]);
|
checkProtocolID(formattedRequest[0]);
|
||||||
|
System.out.print("juste avant le switch");
|
||||||
switch (formattedRequest[1]) {
|
switch (formattedRequest[1]) {
|
||||||
case "LIST":
|
case "LIST":
|
||||||
|
System.out.print("liste detectee");
|
||||||
res += sendFileList();
|
res += sendFileList();
|
||||||
break;
|
break;
|
||||||
case "DOWNLOAD":
|
case "DOWNLOAD":
|
||||||
@ -99,12 +102,13 @@ public class ServerManagementUDP implements Runnable {
|
|||||||
/** Initialize local list of all files allowed to be shared.
|
/** Initialize local list of all files allowed to be shared.
|
||||||
*/
|
*/
|
||||||
private void initFileList() {
|
private void initFileList() {
|
||||||
|
System.out.println(baseDirectory);
|
||||||
File folder = new File(baseDirectory);
|
File folder = new File(baseDirectory);
|
||||||
File[] files = folder.listFiles();
|
File[] files = folder.listFiles();
|
||||||
/* Add non-recursively files's names to fileList */
|
/* Add non-recursively files's names to fileList */
|
||||||
for (int i = 0; i < files.length; i++) {
|
for (File f : files) {
|
||||||
if (files[i].isFile()) {
|
if (f.isFile()) {
|
||||||
fileList.add(files[i].getName());
|
fileList.add(f.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,7 +119,8 @@ public class ServerManagementUDP implements Runnable {
|
|||||||
* @throws ProtocolError
|
* @throws ProtocolError
|
||||||
*/
|
*/
|
||||||
private void checkProtocolID(String msgProtocolID) 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();
|
throw new ProtocolError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,9 +151,9 @@ public class ServerManagementUDP implements Runnable {
|
|||||||
private String sendFileList() {
|
private String sendFileList() {
|
||||||
String res = "LIST\n";
|
String res = "LIST\n";
|
||||||
for (String f : fileList) {
|
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
|
/** Prepare data to be send if protocol error is detected
|
||||||
|
Binary file not shown.
@ -24,9 +24,10 @@ public class ServerP2P {
|
|||||||
} else {
|
} else {
|
||||||
d = ".";
|
d = ".";
|
||||||
}
|
}
|
||||||
d += "P2P_JAVA_PROJECT_SERVER/";
|
d += "/P2P_JAVA_PROJECT_SERVER/";
|
||||||
// create directory if not already exists
|
// create directory if not already exists
|
||||||
new File(d).mkdirs();
|
new File(d).mkdirs();
|
||||||
|
directory = d;
|
||||||
}
|
}
|
||||||
public static void main(String [] args) {
|
public static void main(String [] args) {
|
||||||
ServerP2P s = new ServerP2P();
|
ServerP2P s = new ServerP2P();
|
||||||
|
Loading…
Reference in New Issue
Block a user