From f0707c54125f40112722985cdd3ca9777e051225 Mon Sep 17 00:00:00 2001 From: jianguo Date: Mon, 27 May 2024 16:31:25 +0800 Subject: [PATCH] 0.2.6 fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.bug修复 --- src/main/java/org/aohe/Main.java | 2 +- .../java/org/aohe/core/swing/MainWindow.java | 13 +++++++--- .../java/org/aohe/core/web/SocketFactory.java | 24 ++++++++++--------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/aohe/Main.java b/src/main/java/org/aohe/Main.java index b3b45ee..c355b38 100644 --- a/src/main/java/org/aohe/Main.java +++ b/src/main/java/org/aohe/Main.java @@ -14,7 +14,7 @@ import javax.swing.*; @Slf4j public class Main { - public static void main(String[] args) throws IOException, InterruptedException { + public static void main(String[] args) { log.info(" 当前系统类型: {}", SystemUtils.getOsName()); try { //设置窗口主题 diff --git a/src/main/java/org/aohe/core/swing/MainWindow.java b/src/main/java/org/aohe/core/swing/MainWindow.java index 25c664d..f15393e 100644 --- a/src/main/java/org/aohe/core/swing/MainWindow.java +++ b/src/main/java/org/aohe/core/swing/MainWindow.java @@ -104,14 +104,21 @@ public class MainWindow extends JFrame { } public static void initSocket() { - SocketFactory.start(); + if(SocketFactory.start()){ + setView("socket 服务启动成功"); + }else{ + setView("socket 服务启动失败,请检查8997端口是否被占用"); + } } public void stopSocket() { try { - SocketFactory.stop(); + if(SocketFactory.stop()){ + setView("服务停止成功"); + }else{ + setView("服务停止失败"); + } Thread.sleep(1000); - setView("服务关闭"); log.info("服务关闭"); } catch (InterruptedException e) { throw new RuntimeException(e); diff --git a/src/main/java/org/aohe/core/web/SocketFactory.java b/src/main/java/org/aohe/core/web/SocketFactory.java index 5ce78a5..15a1b74 100644 --- a/src/main/java/org/aohe/core/web/SocketFactory.java +++ b/src/main/java/org/aohe/core/web/SocketFactory.java @@ -28,35 +28,37 @@ public class SocketFactory { * 获取Socket客户端 * @return socketServer */ - private static SocketServer getSocket(){ - try { - log.info("Create Socket ..."); - socketServer = new SocketServer(8997); - } catch (UnknownHostException e) { - throw new RuntimeException(e); - } + private static SocketServer getSocket() throws UnknownHostException { + log.info("Create Socket ..."); + socketServer = new SocketServer(8997); return socketServer; } /** * 启动socket服务 */ - public static void start(){ - getSocket().start(); + public static boolean start() { + try { + getSocket().start(); + } catch (UnknownHostException e) { + return false; + } log.info("socket 已启动"); + return true; } /** * 停止socket服务 */ - public static void stop(){ + public static boolean stop(){ try { if(socketServer != null){ socketServer.stop(); } } catch (InterruptedException e) { - throw new RuntimeException(e); + return false; } + return true; } }