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
a4af4983
Commit
a4af4983
authored
4 years ago
by
ik1g19
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
ClientAndLoggers/ClientMain.java
+1
-5
1 addition, 5 deletions
ClientAndLoggers/ClientMain.java
src/ftp/DStore.java
+12
-6
12 additions, 6 deletions
src/ftp/DStore.java
src/ftp/Server.java
+4
-4
4 additions, 4 deletions
src/ftp/Server.java
with
17 additions
and
15 deletions
ClientAndLoggers/ClientMain.java
+
1
−
5
View file @
a4af4983
...
...
@@ -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
);
}
...
...
This diff is collapsed.
Click to expand it.
src/ftp/DStore.java
+
12
−
6
View file @
a4af4983
...
...
@@ -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();
}
}
This diff is collapsed.
Click to expand it.
src/ftp/Server.java
+
4
−
4
View file @
a4af4983
...
...
@@ -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
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