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
3b6a3faf
Commit
3b6a3faf
authored
9 months ago
by
Brutzman, Don
Browse files
Options
Downloads
Patches
Plain Diff
restore file
parent
5697a09d
No related branches found
Branches containing commit
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
+64
-0
64 additions, 0 deletions
examples/src/TcpExamples/TcpExample4DispatchServer.java
with
64 additions
and
0 deletions
examples/src/TcpExamples/TcpExample4DispatchServer.java
0 → 100644
+
64
−
0
View file @
3b6a3faf
package
TcpExamples
;
import
java.io.IOException
;
import
java.net.*
;
/**
* This server program works a bit differently by creating and dispatching a
* new thread to handle multiple incoming socket connections, one after another, all running in parallel.
* This advanced technique is often used in high=performance high=capacity server programs.
*
* @see TcpExample4Client
* @see TcpExample4HandlerThread
*
* @see <a href="../../../src/TcpExamples/TcpExample4TerminalLog.txt" target="blank">TcpExample4TerminalLog.txt</a>
* @see <a href="../../../src/TcpExamples/TcpExample4SequenceDiagram.png" target="blank">TcpExample4SequenceDiagram.png</a>
* @see <a href="../../../src/TcpExamples/TcpExample4SequenceSketch.png" target="blank">TcpExample4SequenceSketch.png</a>
*
* @author Don McGregor
* @author Don Brutzman
* @author MV3500 class
*/
public
class
TcpExample4DispatchServer
{
/** Default constructor */
public
TcpExample4DispatchServer
()
{
// default constructor
}
/**
* Program invocation, execution starts here
* @param args command-line arguments
*/
public
static
void
main
(
String
[]
args
)
{
try
{
ServerSocket
serverSocket
=
new
ServerSocket
(
2317
);
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
connectionCount
++;
// unblocked, got another connection
System
.
out
.
println
(
"============================================================="
);
System
.
out
.
println
(
TcpExample4DispatchServer
.
class
.
getName
()
+
".handlerThread invocation for connection #"
+
connectionCount
+
"..."
);
handlerThread
=
new
TcpExample4HandlerThread
(
clientConnection
);
handlerThread
.
start
();
// invokes the run() method in that object
System
.
out
.
println
(
TcpExample4DispatchServer
.
class
.
getName
()
+
".handlerThread is launched, awaiting another connection..."
);
}
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
"Problem with "
+
TcpExample4DispatchServer
.
class
.
getName
()
+
" networking:"
);
// describe what is happening
System
.
out
.
println
(
"Error: "
+
e
);
// Provide more helpful information to user if exception occurs due to running twice at one time
if
(
e
instanceof
java
.
net
.
BindException
)
{
System
.
out
.
println
(
"*** Be sure to stop any other running instances of programs using this port!"
);
}
}
System
.
out
.
println
(
"============================================================="
);
}
}
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