From 0e311e49d28c111aee9497e9195f729a716d5f52 Mon Sep 17 00:00:00 2001 From: brutzman <brutzman@nps.edu> Date: Sun, 11 Aug 2024 11:43:15 -0700 Subject: [PATCH] warn if user tries to start client before server --- examples/src/TcpExamples/TcpExample3Client.java | 4 ++++ examples/src/TcpExamples/TcpExample4Client.java | 4 ++++ examples/src/TcpExamples/TcpSentryScenarioClient.java | 11 ++++++++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/examples/src/TcpExamples/TcpExample3Client.java b/examples/src/TcpExamples/TcpExample3Client.java index 7312d3aac7..527f9ce2dd 100644 --- a/examples/src/TcpExamples/TcpExample3Client.java +++ b/examples/src/TcpExamples/TcpExample3Client.java @@ -97,6 +97,10 @@ public class TcpExample3Client if (e instanceof java.net.BindException) { System.err.println("*** Be sure to stop any other running instances of programs using this port!"); } + else if (e instanceof java.net.ConnectException) + { + System.out.println("*** Be sure to start the server before starting the client!"); + } } finally // occurs after any other activity when shutting down { diff --git a/examples/src/TcpExamples/TcpExample4Client.java b/examples/src/TcpExamples/TcpExample4Client.java index 9e4030fe4e..4a7fdb6581 100644 --- a/examples/src/TcpExamples/TcpExample4Client.java +++ b/examples/src/TcpExamples/TcpExample4Client.java @@ -79,6 +79,10 @@ public class TcpExample4Client if (e instanceof java.net.BindException) { System.out.println("*** Be sure to stop any other running instances of programs using this port!"); } + else if (e instanceof java.net.ConnectException) + { + System.out.println("*** Be sure to start the server before starting the client!"); + } } } } diff --git a/examples/src/TcpExamples/TcpSentryScenarioClient.java b/examples/src/TcpExamples/TcpSentryScenarioClient.java index 71507b79d7..20f7fde618 100644 --- a/examples/src/TcpExamples/TcpSentryScenarioClient.java +++ b/examples/src/TcpExamples/TcpSentryScenarioClient.java @@ -112,12 +112,17 @@ public class TcpSentryScenarioClient System.out.println(prefix + " complete"); // main method now exits } catch (IOException e) { - System.out.println("Problem with " + prefix + " networking:networking:"); // describe what is happening - System.out.println("Error: " + e); + System.out.println("*** Problem with " + prefix + "networking:"); // 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) { + if (e instanceof java.net.BindException) + { System.out.println("*** Be sure to stop any other running instances of programs using this port!"); } + else if (e instanceof java.net.ConnectException) + { + System.out.println("*** Be sure to start the server before starting the client!"); + } } } } -- GitLab