Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
socket_chat
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CSCE 361
starter code
socket_chat
Commits
daeec119
Commit
daeec119
authored
5 years ago
by
Christopher Bohn
Browse files
Options
Downloads
Patches
Plain Diff
Fixed small DRY problem; fixed what would've been bug in student code
parent
f422311d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/edu/unl/cse/csce361/socket_chat/Chat.java
+6
-5
6 additions, 5 deletions
src/main/java/edu/unl/cse/csce361/socket_chat/Chat.java
with
6 additions
and
5 deletions
src/main/java/edu/unl/cse/csce361/socket_chat/Chat.java
+
6
−
5
View file @
daeec119
...
...
@@ -220,7 +220,7 @@ public class Chat {
PrintStream
remoteOutput
)
{
// "Connection established. Host goes first."
System
.
out
.
println
(
bundle
.
getString
(
"connection.info.ready"
));
String
message
;
String
message
=
""
;
boolean
keepTalking
=
true
;
boolean
myTurnToTalk
=
isHost
;
try
{
...
...
@@ -229,13 +229,11 @@ public class Chat {
if
(
myTurnToTalk
)
{
message
=
localInput
.
readLine
();
remoteOutput
.
println
(
encipher
(
message
));
keepTalking
=
!
keywords
.
contains
(
message
)
||
handleKeyword
(
message
,
localInput
,
localOutput
);
}
else
{
String
encipheredMessage
=
remoteInput
.
readLine
();
if
(
encipheredMessage
!=
null
)
{
message
=
decipher
(
encipheredMessage
);
localOutput
.
println
(
message
);
keepTalking
=
!
keywords
.
contains
(
message
)
||
handleKeyword
(
message
,
localInput
,
localOutput
);
}
else
{
// "Received null message: lost connection to remote chatter. Terminating."
localOutput
.
println
(
bundle
.
getString
(
"communicate.error.nullMessageFromRemote"
));
...
...
@@ -247,6 +245,9 @@ public class Chat {
localOutput
.
println
(
bundle
.
getString
(
"communicate.error.cannotSendMessage"
));
keepTalking
=
false
;
}
if
(
keepTalking
&&
keywords
.
contains
(
message
))
{
keepTalking
=
handleKeyword
(
message
,
myTurnToTalk
,
localInput
,
localOutput
);
}
myTurnToTalk
=
!
myTurnToTalk
;
}
}
catch
(
IOException
ioException
)
{
...
...
@@ -255,12 +256,12 @@ public class Chat {
}
}
private
boolean
handleKeyword
(
String
keyword
,
BufferedReader
input
,
PrintStream
output
)
{
private
boolean
handleKeyword
(
String
keyword
,
boolean
fromRemote
,
BufferedReader
input
,
PrintStream
output
)
{
if
(
keyword
.
equals
(
bundle
.
getString
(
"communicate.keyword.exit"
)))
{
return
false
;
/*
} else if (keyword.equals(bundle.getString("communicate.keyword.setLocale"))) {
if (
isHost
) {
if (
fromRemote
) {
Prompt user using output.println() (be sure to use i18n properties)
and get response using input.readLine(). Get the appropriate Locale and call
setLocale( ... );
...
...
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