Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NetworkedGraphicsMV3500
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
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
Savage
NetworkedGraphicsMV3500
Commits
502e3d32
Commit
502e3d32
authored
9 months ago
by
Brutzman, Don
Browse files
Options
Downloads
Patches
Plain Diff
improved comments
parent
3159460c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/src/TcpExamples/TcpExample4DispatchServer.java
+13
-7
13 additions, 7 deletions
examples/src/TcpExamples/TcpExample4DispatchServer.java
with
13 additions
and
7 deletions
examples/src/TcpExamples/TcpExample4DispatchServer.java
+
13
−
7
View file @
502e3d32
...
...
@@ -33,27 +33,33 @@ public class TcpExample4DispatchServer
public
static
void
main
(
String
[]
args
)
{
try
{
ServerSocket
serverSocket
=
new
ServerSocket
(
2317
);
ServerSocket
serverSocket
=
new
ServerSocket
(
2317
);
Socket
clientConnectionSocket
;
TcpExample4HandlerThread
handlerThread
;
Socket
clientConnection
;
int
connectionCount
=
0
;
// state variable
System
.
out
.
println
(
TcpExample4DispatchServer
.
class
.
getName
()
+
" ready to accept socket connections..."
);
while
(
true
)
// infinite loop
{
clientConnection
=
serverSocket
.
accept
();
// block! until connected
clientConnection
Socket
=
serverSocket
.
accept
();
// block! until connected
connectionCount
++;
// unblocked, got another connection
// TODO provide initial message *to the client* that we are handing off to a dispatch thread... because that is polite behavior.
// plenty of code in Example3, we will let TcpExample4HandlerThread introduce itself
// TODO option for the student, provide initial message *to the client*
// that we are handing off to a dispatch thread... because that is polite behavior.
// Plenty of code in Example3, we instead let our proxy thread
// TcpExample4HandlerThread introduce itself to the client.
System
.
out
.
println
(
"============================================================="
);
System
.
out
.
println
(
TcpExample4DispatchServer
.
class
.
getName
()
+
".handlerThread created for connection #"
+
connectionCount
+
"..."
);
handlerThread
=
new
TcpExample4HandlerThread
(
clientConnection
);
// hand off the aready-created, connected socket to constructor
// hand off this aready-created and connected socket to constructor
handlerThread
=
new
TcpExample4HandlerThread
(
clientConnectionSocket
);
handlerThread
.
start
();
// invokes the run() method in that object
System
.
out
.
println
(
TcpExample4DispatchServer
.
class
.
getName
()
+
".handlerThread is now dispatched and running, using most recent connection..."
);
// while(true) continue looping, serverSocket is still waiting for another customer client
}
}
catch
(
IOException
e
)
{
...
...
@@ -64,6 +70,6 @@ public class TcpExample4DispatchServer
System
.
out
.
println
(
"*** Be sure to stop any other running instances of programs using this port!"
);
}
}
System
.
out
.
println
(
"============================================================="
);
System
.
out
.
println
(
"============================================================="
);
// execution complete
}
}
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