client is able to close the connection, but the server IS NOT

pull/20/head
Flavien Haas 4 years ago
parent 11fcaa25ea
commit e6d950d16b

@ -123,7 +123,7 @@ public class ClientManagementTCP implements Runnable {
* @throws EmptyFile * @throws EmptyFile
*/ */
private void download(String filename) throws EmptyFile, NotFound, InternalError, UnknownHostException, IOException, TransmissionError, ProtocolError, VersionError, SizeError, InternalRemoteError, ProtocolRemoteError, VersionRemoteError { private void download(String filename) throws EmptyFile, NotFound, InternalError, UnknownHostException, IOException, TransmissionError, ProtocolError, VersionError, SizeError, InternalRemoteError, ProtocolRemoteError, VersionRemoteError {
final long MAX_PARTIAL_SIZE = 1024; final long MAX_PARTIAL_SIZE = 4096;
ProtocolP2PPacketTCP d = new ProtocolP2PPacketTCP((Payload) new LoadRequest(filename, 0, MAX_PARTIAL_SIZE)); ProtocolP2PPacketTCP d = new ProtocolP2PPacketTCP((Payload) new LoadRequest(filename, 0, MAX_PARTIAL_SIZE));
d.sendRequest((Object)socket); d.sendRequest((Object)socket);
boolean fileFullyWritten = false; boolean fileFullyWritten = false;
@ -188,6 +188,7 @@ public class ClientManagementTCP implements Runnable {
throw new ProtocolError(); throw new ProtocolError();
} }
} while(!fileFullyWritten); } while(!fileFullyWritten);
socket.close();
} }
/** list servers directory content /** list servers directory content

@ -121,7 +121,7 @@ public class ClientManagementUDP implements Runnable {
* @throws EmptyFile * @throws EmptyFile
*/ */
private void download(String filename) throws EmptyFile, NotFound, InternalError, UnknownHostException, IOException, TransmissionError, ProtocolError, VersionError, SizeError, InternalRemoteError, ProtocolRemoteError, VersionRemoteError { private void download(String filename) throws EmptyFile, NotFound, InternalError, UnknownHostException, IOException, TransmissionError, ProtocolError, VersionError, SizeError, InternalRemoteError, ProtocolRemoteError, VersionRemoteError {
final long MAX_PARTIAL_SIZE = 1024; final long MAX_PARTIAL_SIZE = 4096;
ProtocolP2PPacketUDP d = new ProtocolP2PPacketUDP((Payload) new LoadRequest(filename, 0, MAX_PARTIAL_SIZE)); ProtocolP2PPacketUDP d = new ProtocolP2PPacketUDP((Payload) new LoadRequest(filename, 0, MAX_PARTIAL_SIZE));
d.sendRequest((Object)socket); d.sendRequest((Object)socket);
boolean fileFullyWritten = false; boolean fileFullyWritten = false;

@ -68,7 +68,7 @@ public class ServerManagementTCP implements Runnable {
try { try {
Socket s = socket.accept(); Socket s = socket.accept();
System.err.println("Accepting new connection"); System.err.println("Accepting new connection");
while(true) { do {
try { try {
ProtocolP2PPacketTCP pd = new ProtocolP2PPacketTCP((Object)s); ProtocolP2PPacketTCP pd = new ProtocolP2PPacketTCP((Object)s);
Payload p = pd.getPayload(); Payload p = pd.getPayload();
@ -139,14 +139,17 @@ public class ServerManagementTCP implements Runnable {
default: default:
sendInternalError(pd); sendInternalError(pd);
} }
} catch (IOException e) { } catch (SocketException e) {
} catch (TransmissionError e) { System.out.println("connection closed");
} catch (ProtocolError e) { s.close();
} catch (VersionError e) {
} catch (InternalError e) {
} catch (SizeError e) {
} }
} catch (IOException e) {}
catch (TransmissionError e) {}
catch (ProtocolError e) {}
catch (VersionError e) {}
catch (InternalError e) {}
catch (SizeError e) {}
} while(true);
} catch (IOException e) { } catch (IOException e) {
} }
} }
@ -168,8 +171,6 @@ public class ServerManagementTCP implements Runnable {
Arrays.sort(fileList); Arrays.sort(fileList);
} }
/** Send an internal error message. /** Send an internal error message.
* @param pd ProtocolP2PPacketTCP to respond * @param pd ProtocolP2PPacketTCP to respond
*/ */
@ -182,4 +183,3 @@ public class ServerManagementTCP implements Runnable {
} }
} }

Loading…
Cancel
Save