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
745ae316
Commit
745ae316
authored
7 months ago
by
Brutzman, Don
Browse files
Options
Downloads
Patches
Plain Diff
demonstrate NetBeans javadoc Analyzer
parent
da692916
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
assignments/src/MV3500Cohort2024JulySeptember/homework2/Timberlake/Server_HW2.java
+63
-60
63 additions, 60 deletions
...ort2024JulySeptember/homework2/Timberlake/Server_HW2.java
with
63 additions
and
60 deletions
assignments/src/MV3500Cohort2024JulySeptember/homework2/Timberlake/Server_HW2.java
+
63
−
60
View file @
745ae316
package
MV3500Cohort2024JulySeptember.homework2.Timberlake
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
/**
* 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 Client_HW2
* @see GameHandler
*
* @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
* @author Jack Timberlake
*/
public
class
Server_HW2
{
public
static
void
main
(
String
[]
args
)
{
ServerSocket
serverSocket
=
null
;
try
{
// Create a socket to listen on port 9876
serverSocket
=
new
ServerSocket
(
9876
);
System
.
out
.
println
(
"Server has started, waiting for client..."
);
while
(
true
)
{
// Accept client connection
Socket
clientSocket
=
serverSocket
.
accept
();
System
.
out
.
println
(
"Client connected"
);
// Create GameHandler to handle client
GameHandler
gameHandler
=
new
GameHandler
(
clientSocket
);
// Create new thread to handle the game
Thread
thread
=
new
Thread
(
gameHandler
);
thread
.
start
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
// Print any exceptions that occur
}
finally
{
try
{
if
(
serverSocket
!=
null
&&
!
serverSocket
.
isClosed
())
{
serverSocket
.
close
();
// Close the server socket to release resources
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
}
package
MV3500Cohort2024JulySeptember.homework2.Timberlake
;
import
java.io.IOException
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
/**
* 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 Client_HW2
* @see GameHandler
*
* @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
* @author Jack Timberlake
*/
public
class
Server_HW2
{
/** The main method launches the program from the command line, no parameters needed.
* @param args command-line arguments, none needed */
public
static
void
main
(
String
[]
args
)
{
ServerSocket
serverSocket
=
null
;
try
{
// Create a socket to listen on port 9876
serverSocket
=
new
ServerSocket
(
9876
);
System
.
out
.
println
(
"Server has started, waiting for client..."
);
while
(
true
)
{
// Accept client connection
Socket
clientSocket
=
serverSocket
.
accept
();
System
.
out
.
println
(
"Client connected"
);
// Create GameHandler to handle client
GameHandler
gameHandler
=
new
GameHandler
(
clientSocket
);
// Create new thread to handle the game
Thread
thread
=
new
Thread
(
gameHandler
);
thread
.
start
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
// Print any exceptions that occur
}
finally
{
try
{
if
(
serverSocket
!=
null
&&
!
serverSocket
.
isClosed
())
{
serverSocket
.
close
();
// Close the server socket to release resources
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
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