Test & debug
Transfert de fichier réalisé !!
This commit is contained in:
parent
2d20357150
commit
648cb12953
@ -125,6 +125,7 @@ public class ClientManagementUDP implements Runnable {
|
||||
throw new ProtocolError();
|
||||
}
|
||||
if (fp.getOffset() != 0 || fp.getPartialContent().length != fp.getTotalSize()) {
|
||||
System.err.println("offset: " + fp.getOffset() + " ; content.length: " + fp.getPartialContent().length + " ; totalSize: " + fp.getTotalSize());
|
||||
System.err.println("Error: cannot handle partial files (not implemented)");
|
||||
throw new InternalError();
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ public class FilePart extends Payload {
|
||||
int start = 28 + getFilenameSize(datagram); // this can throw SizeError or ProtocolError
|
||||
int end = 8 + getPayloadSize(datagram); // this can throw SizeError
|
||||
try {
|
||||
partialContent = Arrays.copyOfRange(datagram, start, end+1);
|
||||
partialContent = Arrays.copyOfRange(datagram, start, end);
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
throw new ProtocolError();
|
||||
}
|
||||
|
@ -78,6 +78,13 @@ public class ProtocolP2PDatagram {
|
||||
socket.send(datagramPacket);
|
||||
}
|
||||
|
||||
/** Send a response.
|
||||
* @param socket DatagramSocket used to send response
|
||||
* @param host host to send response
|
||||
* @param port port to send response
|
||||
* @throws InternalError
|
||||
* @throws IOException
|
||||
*/
|
||||
protected void sendResponse(DatagramSocket socket, InetAddress host, int port) throws InternalError, IOException {
|
||||
assert port != 0 && host != null : "This method should be used only as response to a request";
|
||||
if (port == 0 || host == null) {
|
||||
|
@ -23,8 +23,8 @@ public class BytesArrayTools {
|
||||
* @param value long to write
|
||||
*/
|
||||
public static void write(byte[] array, int start, long value) {
|
||||
for(int i=0;i<4;i++) {
|
||||
array[start + i] = (byte) ((value >> (8 * (4 - i))) & 0xFF);
|
||||
for(int i=0;i<8;i++) {
|
||||
array[start + i] = (byte) ((value >> (8 * (7 - i))) & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ public class BytesArrayTools {
|
||||
public static int readInt(byte[] array, int start) throws SizeError {
|
||||
int size = 0;
|
||||
for(int i=0;i<4;i++) {
|
||||
size |= ((int)array[start + i]) << (8* i);
|
||||
size |= ((int)array[start + i]) << (8* (3 -i));
|
||||
}
|
||||
if (size < 0) {
|
||||
// Size in array is probably correct
|
||||
@ -53,7 +53,7 @@ public class BytesArrayTools {
|
||||
public static long readLong(byte[] array, int start) throws SizeError {
|
||||
long size = 0;
|
||||
for(int i=0;i<8;i++) {
|
||||
size |= ((int)array[start + i]) << (8* i);
|
||||
size |= ((int)array[start + i]) << (8* (7 - i));
|
||||
}
|
||||
if (size < 0) {
|
||||
// Size in array is probably correct
|
||||
|
Loading…
Reference in New Issue
Block a user