From e774ef57921f14b8e32026cea1c7834e2cf35b3b Mon Sep 17 00:00:00 2001
From: "Norbraten, Terry" <tdnorbra@nps.edu>
Date: Tue, 18 Aug 2020 15:44:45 -0700
Subject: [PATCH] close socket

---
 examples/src/TcpExamples/TcpExample3Client.java | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/examples/src/TcpExamples/TcpExample3Client.java b/examples/src/TcpExamples/TcpExample3Client.java
index a5841c8d28..cb346fa083 100644
--- a/examples/src/TcpExamples/TcpExample3Client.java
+++ b/examples/src/TcpExamples/TcpExample3Client.java
@@ -22,7 +22,7 @@ public class TcpExample3Client {
     public static void main(String[] args) {
         
         // Local variables/fields
-        Socket socket;
+        Socket socket = null;
         InputStream is;
         InputStreamReader isr;
         BufferedReader br;
@@ -72,6 +72,11 @@ public class TcpExample3Client {
         }
         finally // occurs after any other activity when shutting down
         {
+            try {
+                if (socket != null)
+                    socket.close();
+            } catch (IOException e) {}
+            
             // program exit: tell somebody about that happening.  Likely cause: server drops connection.
             System.out.println();
             System.out.println("TcpExample3Client exit");
-- 
GitLab