diff --git a/assignments/src/MV3500Cohort2024JulySeptember/homework2/Timberlake/Server_HW2.java b/assignments/src/MV3500Cohort2024JulySeptember/homework2/Timberlake/Server_HW2.java index 36ed7fa156d1c6f7b6fbc568214f51ce66937633..b54646d3c91cd0a6731e514bf090576fb8379c2e 100644 --- a/assignments/src/MV3500Cohort2024JulySeptember/homework2/Timberlake/Server_HW2.java +++ b/assignments/src/MV3500Cohort2024JulySeptember/homework2/Timberlake/Server_HW2.java @@ -1,60 +1,63 @@ -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(); + } + } + } +} + +