Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
distributed systems cw
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ik1g19
distributed systems cw
Commits
3113e1df
Commit
3113e1df
authored
4 years ago
by
ik1g19
Browse files
Options
Downloads
Patches
Plain Diff
connections close correctly
parent
90bb8a1f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/ftp/Controller.java
+14
-7
14 additions, 7 deletions
src/ftp/Controller.java
src/ftp/DStore.java
+5
-0
5 additions, 0 deletions
src/ftp/DStore.java
src/ftp/Server.java
+13
-3
13 additions, 3 deletions
src/ftp/Server.java
with
32 additions
and
10 deletions
src/ftp/Controller.java
+
14
−
7
View file @
3113e1df
...
...
@@ -117,22 +117,29 @@ public class Controller extends Server {
file
.
setStoreAcksQuota
(
r
);
send
(
"STORE_TO "
+
ports
,
client
);
}
else
if
(
command
.
equals
(
"STORE_ACK"
))
{
String
filename
=
args
[
1
];
DStoreFile
file
=
fileIndex
.
get
(
filename
);
file
.
storeAck
();
Boolean
fileStored
=
false
;
while
(!
fileStored
)
{
if
(
file
.
ackCheck
())
{
file
.
setStoreInProgress
(
false
);
file
.
setStoreComplete
(
true
);
fileStored
=
true
;
threadIDOutput
(
"Store of file "
+
filename
+
" complete"
);
send
(
"STORE_COMPLETE"
,
client
);
}
}
}
else
if
(
command
.
equals
(
"STORE_ACK"
))
{
String
filename
=
args
[
1
];
DStoreFile
file
=
fileIndex
.
get
(
filename
);
file
.
storeAck
();
}
else
if
(
command
.
equals
(
"LOAD"
))
{
String
filename
=
args
[
1
];
...
...
This diff is collapsed.
Click to expand it.
src/ftp/DStore.java
+
5
−
0
View file @
3113e1df
...
...
@@ -104,6 +104,9 @@ public class DStore extends Server {
String
response
=
readSocket
(
client
);
if
(
response
.
equals
(
"ACK"
))
threadIDOutput
(
"Successfully joined Controller"
);
closeConnection
(
client
);
}
else
if
(
command
.
equals
(
"STORE"
))
{
...
...
@@ -125,6 +128,8 @@ public class DStore extends Server {
if
(
controller
!=
null
)
{
send
(
"STORE_ACK "
+
filename
,
controller
);
}
else
threadIDErr
(
"Unable to connect to Controller"
);
closeConnection
(
controller
);
}
else
if
(
command
.
equals
(
"LOAD_DATA"
))
{
...
...
This diff is collapsed.
Click to expand it.
src/ftp/Server.java
+
13
−
3
View file @
3113e1df
...
...
@@ -21,9 +21,13 @@ public abstract class Server {
public
void
run
()
{
try
{
threadIDOutput
(
"Connection Accepted"
);
Boolean
closed
=
false
;
while
(!
closed
)
{
String
request
=
readSocket
(
client
);
handleRequest
(
request
,
client
);
client
.
close
();
if
(
request
==
null
)
closed
=
true
;
else
handleRequest
(
request
,
client
);
}
closeConnection
(
client
);
}
catch
(
Exception
e
)
{
threadIDErr
(
"Exception thrown: "
+
e
.
getMessage
());
}
...
...
@@ -98,4 +102,10 @@ public abstract class Server {
System
.
err
.
println
(
"Thread ID: "
+
Thread
.
currentThread
().
getId
()
+
" "
+
output
);
}
protected
void
closeConnection
(
Socket
client
)
{
try
{
client
.
close
();
threadIDOutput
(
"Connection Closed"
);}
catch
(
IOException
e
)
{
threadIDErr
(
e
.
getMessage
());}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment