diff --git a/CourseExamples/src/TcpExamples/TcpExample2ConnectionCounting.java b/CourseExamples/src/TcpExamples/TcpExample2ConnectionCounting.java index 7718c5d24fd056ee778ab675a1d42eeb92a0271f..897fe538f7ec8c0c03a63e75776d659decb76074 100644 --- a/CourseExamples/src/TcpExamples/TcpExample2ConnectionCounting.java +++ b/CourseExamples/src/TcpExamples/TcpExample2ConnectionCounting.java @@ -18,11 +18,10 @@ import java.net.*; * <code>telnet ipOfServersLaptop 2317</code> * * And have that machine display the socket pairs received. - * @author mcgredo + * @author mcgredo, brutzman */ public class TcpExample2ConnectionCounting { - public static void main(String[] args) { try @@ -31,8 +30,7 @@ public class TcpExample2ConnectionCounting System.out.println(" enter (nc localhost 2317) or (telnet localhost 2317)..." ); // ServerSocket waits for a connection from a client. - // Notice that it is outside the loop; ServerSocket - // needs to be made only once. + // Notice that it is outside the loop; ServerSocket needs to be made only once. int connectionCount = 0; // state variable @@ -55,9 +53,8 @@ public class TcpExample2ConnectionCounting ps.println("You were connection #" + connectionCount + ", by my count"); - // Print some information locally about the Socket - // connection. This includes the port and IP numbers - // on both sides (the socket pair.) + // Print some information locally about the Socket connection. + // This includes the port and IP numbers on both sides (the socket pair.) InetAddress localAddress = clientConnection.getLocalAddress(); InetAddress remoteAddress = clientConnection.getInetAddress(); @@ -69,8 +66,7 @@ public class TcpExample2ConnectionCounting // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 )) note IPv6 // 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? + // Why is first IP/port the same, while the second set has different ports? System.out.println("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " + remoteAddress.toString() + ", " + remotePort + " ))"); @@ -85,7 +81,7 @@ public class TcpExample2ConnectionCounting clientConnection.close(); } } - catch(Exception e) + catch(IOException e) { System.out.println("problem with networking: " + e); }