more TEditor stubs
[nikiroo-utils.git] / src / jexer / demos / Demo2.java
index 81a458d90057f822570f3e9eea750eb013a7f601..b6572af2e9b435cd3946cc909121101c1b132f30 100644 (file)
@@ -3,7 +3,7 @@
  *
  * The MIT License (MIT)
  *
- * Copyright (C) 2016 Kevin Lamonte
+ * Copyright (C) 2017 Kevin Lamonte
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -44,6 +44,7 @@ public class Demo2 {
      * @param args Command line arguments
      */
     public static void main(final String [] args) {
+        ServerSocket server = null;
         try {
             if (args.length == 0) {
                 System.err.printf("USAGE: java -cp jexer.jar jexer.demos.Demo2 port\n");
@@ -51,7 +52,7 @@ public class Demo2 {
             }
 
             int port = Integer.parseInt(args[0]);
-            ServerSocket server = new TelnetServerSocket(port);
+            server = new TelnetServerSocket(port);
             while (true) {
                 Socket socket = server.accept();
                 System.out.printf("New connection: %s\n", socket);
@@ -64,6 +65,14 @@ public class Demo2 {
             }
         } catch (Exception e) {
             e.printStackTrace();
+        } finally {
+            if (server != null) {
+                try {
+                    server.close();
+                } catch (Exception e) {
+                    // SQUASH
+                }
+            }
         }
     }