From 9bbb4b11c3bdb5b9b32a924b1805e916d427f75f Mon Sep 17 00:00:00 2001 From: brutzman <brutzman@nps.edu> Date: Thu, 2 Aug 2018 08:44:49 -0700 Subject: [PATCH] classroom touchups --- .../Server/TcpServer/src/tcpserver/TcpServer.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/projects/TcpExample3/Server/TcpServer/src/tcpserver/TcpServer.java b/projects/TcpExample3/Server/TcpServer/src/tcpserver/TcpServer.java index 9d0ca372d1..b8a77f146c 100644 --- a/projects/TcpExample3/Server/TcpServer/src/tcpserver/TcpServer.java +++ b/projects/TcpExample3/Server/TcpServer/src/tcpserver/TcpServer.java @@ -31,17 +31,21 @@ public class TcpServer { // Notice that it is outside the loop; ServerSocket // needs to be made only once. + System.out.println("TcpServer has started..."); // it helps debugging to put this on console first ServerSocket serverSocket = new ServerSocket(2317); + // Server is up and waiting (i.e. "blocked" or paused) // Loop, infinitely, waiting for client connections. // Stop the program somewhere else. while (true) { - Socket clientConnection = serverSocket.accept(); // block until connected + Socket clientConnection = serverSocket.accept(); // block until connected to a client + + // Now hook everything up (i.e. set up the streams), Java style: OutputStream os = clientConnection.getOutputStream(); - PrintStream ps = new PrintStream(os); + PrintStream ps = new PrintStream(os); - ps.println("This was written by the server"); + ps.println("This was written by the server"); // this goes back to client! // Print some information locally about the Socket // connection. This includes the port and IP numbers -- GitLab