Skip to content
Snippets Groups Projects
Commit a4af4983 authored by ik1g19's avatar ik1g19
Browse files

fixed bug causing client sockets to close before they should

parent 3113e1df
No related branches found
No related tags found
No related merge requests found
......@@ -12,12 +12,8 @@ public class ClientMain {
if (!downloadFolder.exists())
if (!downloadFolder.mkdir()) throw new RuntimeException("Cannot create download folder (folder absolute path: " + downloadFolder.getAbsolutePath() + ")");
File uploadFolder = new File("to_store");
if (!uploadFolder.exists())
throw new RuntimeException("to_store folder does not exist");
testClient(cport, timeout, downloadFolder);
testClient(cport, timeout, downloadFolder, uploadFolder);
}
......
......@@ -106,7 +106,7 @@ public class DStore extends Server {
if (response.equals("ACK")) threadIDOutput("Successfully joined Controller");
closeConnection(client);
closeConnection("Client", client);
}
else if (command.equals("STORE")) {
......@@ -129,7 +129,7 @@ public class DStore extends Server {
send("STORE_ACK " + filename, controller);
} else threadIDErr("Unable to connect to Controller");
closeConnection(controller);
closeConnection("Controller", controller);
}
else if (command.equals("LOAD_DATA")) {
......@@ -155,7 +155,7 @@ public class DStore extends Server {
FileOutputStream out = new FileOutputStream(outputFile);
threadIDOutput("Starting file Read...");
threadIDOutput("Starting file Write...");
while ((buflen = in.read(buf)) != -1) {
out.write(buf,0,buflen);
......@@ -164,7 +164,8 @@ public class DStore extends Server {
threadIDOutput("Finished file Write");
in.close(); out.close();
//in.close();
out.close();
}
......@@ -178,13 +179,18 @@ public class DStore extends Server {
byte[] buf = new byte[1000]; int buflen;
threadIDOutput("Starting file Send");
while ((buflen = inf.read(buf)) != -1) {
out.write(buf, 0, buflen);
}
threadIDOutput("Finished file Send");
inf.close(); client.close(); out.close();
inf.close();
//client.close();
//out.close();
}
}
......@@ -27,7 +27,7 @@ public abstract class Server {
if (request == null) closed = true;
else handleRequest(request, client);
}
closeConnection(client);
closeConnection("Client", client);
} catch (Exception e) {
threadIDErr("Exception thrown: " + e.getMessage());
}
......@@ -86,7 +86,7 @@ public abstract class Server {
threadIDOutput("Recieved: " + request);
}
catch (IOException e) {
threadIDErr("Error: " + e);
threadIDErr("Read Socket Error: " + e);
}
return request;
......@@ -104,8 +104,8 @@ public abstract class Server {
protected void closeConnection(Socket client) {
try {client.close(); threadIDOutput("Connection Closed");} catch (IOException e) {threadIDErr(e.getMessage());}
protected void closeConnection(String name, Socket client) {
try {client.close(); threadIDOutput(name + " Socket Closed");} catch (IOException e) {threadIDErr(e.getMessage());}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment