diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework1/BrutzmanRefactorTcpExample1Telnet.java b/assignments/src/MV3500Cohort2019JulySeptember/homework1/BrutzmanRefactorTcpExample1Telnet.java index 9ba71c1cf56190b803a67930ca533075dcda1c07..ab8e1ff23b6adcd30f63084d2b543bc6d753da6e 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework1/BrutzmanRefactorTcpExample1Telnet.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework1/BrutzmanRefactorTcpExample1Telnet.java @@ -65,9 +65,15 @@ public class BrutzmanRefactorTcpExample1Telnet catch(IOException e) { System.out.println("problem with networking: " + e); -// if (e.getClass() == java.net.BindException) // TODO whazzup? - if (e.getMessage().equals("Address already in use: NET_Bind")) - System.out.println("Be sure to stop any other running instances of this program."); + + // Program modification: provide more helpful information to user if + // exception occurs when running twice at one time + + // brute force exception checking, can be brittle if exection message changes + // if (e.getMessage().equals("Address already in use: NET_Bind")) + + if (e instanceof java.net.BindException) + System.out.println("Be sure to stop any other running instances of this program!"); } } } diff --git a/examples/src/TcpExamples/TcpExample1Telnet.java b/examples/src/TcpExamples/TcpExample1Telnet.java index 373c0f58ebb4345af3c4dcdeb79f1206ffb11706..4badbe705b59ae6f634aa5f7d536d70ffc6395b9 100644 --- a/examples/src/TcpExamples/TcpExample1Telnet.java +++ b/examples/src/TcpExamples/TcpExample1Telnet.java @@ -64,7 +64,10 @@ public class TcpExample1Telnet } catch(IOException e) { - System.out.println("problem with networking: " + e); + System.out.println("*** Problem with networking: " + e); + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) + System.out.println("*** Be sure to stop any other running instances of this program!"); } } } diff --git a/examples/src/TcpExamples/TcpExample2ConnectionCounting.java b/examples/src/TcpExamples/TcpExample2ConnectionCounting.java index 14504d55a242429b2b359c6da43a5ef5cde9f923..8a3a4a762a4e39a1c978084a348519e729d59fdf 100644 --- a/examples/src/TcpExamples/TcpExample2ConnectionCounting.java +++ b/examples/src/TcpExamples/TcpExample2ConnectionCounting.java @@ -85,6 +85,9 @@ public class TcpExample2ConnectionCounting catch(IOException e) { System.out.println("problem with networking: " + e); + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) + System.out.println("*** Be sure to stop any other running instances of this program!"); } } } diff --git a/examples/src/TcpExamples/TcpExample3Client.java b/examples/src/TcpExamples/TcpExample3Client.java index 87e44dae4ce5de6b80532253e6d2c109ad20e121..550b8d5288873c73df3d224f776bfa250c24fa58 100644 --- a/examples/src/TcpExamples/TcpExample3Client.java +++ b/examples/src/TcpExamples/TcpExample3Client.java @@ -48,6 +48,9 @@ public class TcpExample3Client { catch (IOException e) { System.out.println("Problem with client: "); // describe what is happening System.out.println(e); + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) + System.out.println("*** Be sure to stop any other running instances of this program!"); } // program exit: tell somebody about that System.out.println("client exit"); diff --git a/examples/src/TcpExamples/TcpExample3Server.java b/examples/src/TcpExamples/TcpExample3Server.java index eeccda6f4bb813ebb8c1296b6424a9837832bd9d..b948f8e0269dffb3dc98c9854e547b1132584eef 100644 --- a/examples/src/TcpExamples/TcpExample3Server.java +++ b/examples/src/TcpExamples/TcpExample3Server.java @@ -73,8 +73,12 @@ public class TcpExample3Server { clientConnection.close(); // like it or not, you're outta here! } } - catch (IOException e) { + catch (IOException e) + { System.out.println("problem with networking"); + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) + System.out.println("*** Be sure to stop any other running instances of this program!"); } } }