From 819940c20dfb8a0c797b3423a3c0a0c67c9fd955 Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期五, 27 十二月 2024 18:06:23 +0800
Subject: [PATCH] 处理后台运行被释放的问题

---
 app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpService.java |   32 +++++++++++++++++++++++++++++++-
 1 files changed, 31 insertions(+), 1 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpService.java b/app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpService.java
index 748140a..99228dc 100644
--- a/app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpService.java
+++ b/app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpService.java
@@ -4,9 +4,20 @@
 import android.content.Intent;
 import android.os.Binder;
 import android.os.IBinder;
+import android.text.TextUtils;
 
 import androidx.annotation.Nullable;
 
+import com.hdl.photovoltaic.other.HdlLogLogic;
+
+import org.w3c.dom.Text;
+
+import java.io.IOException;
+import java.util.Objects;
+
+/**
+ * 鏈湴鏈嶅姟鍣�
+ */
 public class MyNanoHttpService extends Service {
     private MyNanoHttpServer myNanoHttpServer = MyNanoHttpServer.getInstance(null);
 
@@ -18,7 +29,26 @@
         try {
             myNanoHttpServer.start();
         } catch (Exception e) {
-            e.printStackTrace();
+//            if (myNanoHttpServer!=null&&myNanoHttpServer.gserverSocket.isBound() && !serverSocket.isClosed()) {
+//                // Port is available
+//            } else {
+//                // Port is not available
+//            }
+//            e.printStackTrace();
+//            if (!TextUtils.isEmpty(e.getMessage()) && Objects.requireNonNull(e.getMessage()).contains("Address already in use")) {
+//                myNanoHttpServer = null;
+//                for (int i = MyNanoHttpServer.HTTP_PORT + 1; i < 65535; i++) {
+//                    try {
+//                        MyNanoHttpServer.HTTP_PORT = i;
+//                        myNanoHttpServer = MyNanoHttpServer.getInstance(null);
+//                        myNanoHttpServer.start();
+//                    } catch (Exception ex) {
+//                        String s = ex.getMessage();
+//                    }
+//                }
+//
+//            }
+            HdlLogLogic.print("鍒濆鍖朒ttp鏈嶅姟鍣ㄥけ璐�---" + e.getMessage(), true);
             startService(new Intent(this, MyNanoHttpService.class));
         }
     }

--
Gitblit v1.8.0