Skip to content
Snippets Groups Projects
Commit 37dfa99f authored by brutzman's avatar brutzman
Browse files

cleanup comments, warnings

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