Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
COM2022 Implementations
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ramkumar, Ragulan (UG - Comp Sci & Elec Eng)
COM2022 Implementations
Commits
a687ee8a
Commit
a687ee8a
authored
3 years ago
by
Ramkumar, Ragulan (UG - Comp Sci & Elec Eng)
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
abe0fa59
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Client.java
+54
-0
54 additions, 0 deletions
Client.java
with
54 additions
and
0 deletions
Client.java
0 → 100644
+
54
−
0
View file @
a687ee8a
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.io.PrintWriter
;
import
java.net.Socket
;
/**
* @author Ragulan Ramkumar (rr00663)
*/
public
class
Client
{
private
static
final
String
SERVER_IP
=
"127.0.0.1"
;
private
static
final
int
SERVER_PORT
=
60000
;
public
static
void
main
(
String
[]
args
)
throws
IOException
,
InterruptedException
{
String
UUID
;
Socket
socket
=
new
Socket
(
SERVER_IP
,
SERVER_PORT
);
BufferedReader
input
=
new
BufferedReader
(
new
InputStreamReader
(
socket
.
getInputStream
()));
BufferedReader
userKeyboardInput
=
new
BufferedReader
(
new
InputStreamReader
(
System
.
in
));
PrintWriter
output
=
new
PrintWriter
(
socket
.
getOutputStream
(),
true
);
System
.
out
.
println
(
"Connected to the server.\nSend HELLO to get a place in the queue."
);
while
(
true
)
{
System
.
out
.
print
(
"--> "
);
String
userInput
=
userKeyboardInput
.
readLine
();
// Fix entering empty line crashing
if
(
userInput
.
equals
(
""
))
{
continue
;
}
output
.
println
(
userInput
);
while
(
true
)
{
// Interpret the messages here
String
response
=
input
.
readLine
();
if
(
response
.
equals
(
""
))
{
break
;
}
System
.
out
.
println
(
"<-- From server: "
+
response
);
if
(
response
.
equals
(
"UNKNOWN_COMMAND"
))
{
}
if
(
response
.
startsWith
(
"UUID"
))
{
UUID
=
response
.
substring
(
5
,
response
.
length
());
System
.
out
.
println
(
"Your UUID is "
+
UUID
+
"\nYou'll need this to renter the queue later."
);
}
if
(
response
.
equals
(
"NEXT"
))
{
System
.
out
.
println
(
"It's your turn. Send DONE when complete."
);
}
if
(
response
.
equals
(
"GOODBYE"
))
{
System
.
out
.
println
(
"Closing connection"
);
output
.
close
();
input
.
close
();
}
}
}
}
}
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