diff --git a/examples/src/TcpExamples/TcpExample3Server.java b/examples/src/TcpExamples/TcpExample3Server.java index 7bd494ba388b8b678447907e889b10a9d4ee3960..8afc2f5be3698eb50ff0350b22e7d3eb590f38fb 100644 --- a/examples/src/TcpExamples/TcpExample3Server.java +++ b/examples/src/TcpExamples/TcpExample3Server.java @@ -20,6 +20,7 @@ import java.net.*; * and have the instructor display the socket pairs received. * * @author mcgredo + * @author brutzman */ public class TcpExample3Server { @@ -52,18 +53,24 @@ public class TcpExample3Server { // Print some information locally about the Socket connection. // This includes the port and IP numbers on both sides (the socket pair). - localAddress = clientConnection.getLocalAddress(); + localAddress = clientConnection.getLocalAddress(); remoteAddress = clientConnection.getInetAddress(); - localPort = clientConnection.getLocalPort(); - remotePort = clientConnection.getPort(); + localPort = clientConnection.getLocalPort(); + remotePort = clientConnection.getPort(); // My socket pair connection looks like this, to localhost: // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 )) // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) // Why is the first IP/port the same, while the second set has different ports? - System.out.println("TcpExample3Server socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " - + remoteAddress.toString() + ", " + remotePort + " ))"); + System.out.println("TcpExample3Server socket pair showing host name, address, port:"); + System.out.println(" (( " + + localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( " + + remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))"); + + if ( localAddress.getHostName().equals( localAddress.getHostAddress()) || + remoteAddress.getHostName().equals(remoteAddress.getHostAddress())) + System.out.println(" note HostName matches address if host has no DNS name"); // Notice the use of flush() and try w/ resources. Without // the try w/ resources the Socket object may stay open for