Skip to content
Snippets Groups Projects
Commit d6b412f2 authored by Brutzman, Don's avatar Brutzman, Don
Browse files

explanatory comments

parent 5f82b7f9
No related branches found
No related tags found
No related merge requests found
...@@ -58,7 +58,7 @@ public class TcpExample1Telnet ...@@ -58,7 +58,7 @@ public class TcpExample1Telnet
// The Socket object represents the connection between // The Socket object represents the connection between
// the server and client, including a full duplex connection // the server and client, including a full duplex connection
try (Socket clientConnection = serverSocket.accept()) // wait here for a client to connect try (Socket clientConnection = serverSocket.accept()) // listen, wait here for a client to connect
{ {
// OK we got something, time to respond! // OK we got something, time to respond!
// Use Java io classes to write text (as opposed to // Use Java io classes to write text (as opposed to
......
...@@ -36,6 +36,7 @@ public class TcpExample2ConnectionCounting ...@@ -36,6 +36,7 @@ public class TcpExample2ConnectionCounting
{ {
try try
{ {
// welcome aboard messages
System.out.println("TcpExample2ConnectionCounting has started and is waiting for a connection."); System.out.println("TcpExample2ConnectionCounting has started and is waiting for a connection.");
System.out.println(" help: https://savage.nps.edu/Savage/developers.html#telnet"); System.out.println(" help: https://savage.nps.edu/Savage/developers.html#telnet");
System.out.println(" Windows ipconfig (or Mac ifconfig) indicates current IPv4_Address (for example local wireless IP address)"); System.out.println(" Windows ipconfig (or Mac ifconfig) indicates current IPv4_Address (for example local wireless IP address)");
...@@ -56,8 +57,8 @@ public class TcpExample2ConnectionCounting ...@@ -56,8 +57,8 @@ public class TcpExample2ConnectionCounting
while(true) while(true)
{ {
// serverSocket.accept() blocks! then proceeds once a connection is "accept"ed // serverSocket.accept() blocks! then proceeds once a connection is "accept"ed
try (Socket clientConnection = serverSocket.accept()) { try (Socket clientConnection = serverSocket.accept()) { // the accept() method blocks here until a client connects
connectionCount++; // got another one! connectionCount++; // got another one! a client has connected
OutputStream os = clientConnection.getOutputStream(); OutputStream os = clientConnection.getOutputStream();
PrintStream ps = new PrintStream(os); PrintStream ps = new PrintStream(os);
...@@ -109,7 +110,7 @@ public class TcpExample2ConnectionCounting ...@@ -109,7 +110,7 @@ public class TcpExample2ConnectionCounting
ps.flush(); ps.flush();
} }
} }
} }
catch(IOException e) catch(IOException e)
{ {
System.err.println("Problem with " + TcpExample2ConnectionCounting.class.getName() + " networking:"); // describe what is happening System.err.println("Problem with " + TcpExample2ConnectionCounting.class.getName() + " networking:"); // describe what is happening
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment