diff --git a/examples/src/TcpExamples/TcpExample2ConnectionCounting.java b/examples/src/TcpExamples/TcpExample2ConnectionCounting.java index 988aac7e8f7a288b1ea201bf208a239c5748d999..478508c9f768ba7c8882b3f0327db22ec303f02e 100644 --- a/examples/src/TcpExamples/TcpExample2ConnectionCounting.java +++ b/examples/src/TcpExamples/TcpExample2ConnectionCounting.java @@ -33,7 +33,16 @@ public class TcpExample2ConnectionCounting { 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(" enter (nc localhost 2317) or (telnet localhost 2317)..." ); + // Where are we? In other words, what is our host number? Advertise it + // https://stackoverflow.com/questions/9481865/getting-the-ip-address-of-the-current-machine-using-java + String localHostAddress = Inet4Address.getLocalHost().toString(); + System.out.println("Local host address is " + localHostAddress); + if (localHostAddress.contains("/")) + localHostAddress = localHostAddress.substring(localHostAddress.indexOf("/")+1); + // show localhost IP number to facilitate connections over local area network (LAN, WAN) + System.out.println(" enter (nc localhost 2317) or (telnet localhost 2317) for local operation" ); + System.out.println(" enter (nc " + localHostAddress + " 2317) or " + + "(telnet " + localHostAddress + " 2317)..." ); // ServerSocket waits for a connection from a client. // Notice that it is outside the loop; ServerSocket needs to be made only once. @@ -42,7 +51,7 @@ public class TcpExample2ConnectionCounting ServerSocket serverSocket = new ServerSocket(2317); // server decides here what port to listen on. // of interest: often client doesn't care what port it uses locally when connecting to that server port. - + // Loop, infinitely, waiting for client connections. // Stop the program somewhere else. while(true)