limeng před 2 roky
rodič
revize
6f343b0a58

+ 1 - 10
ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java

@@ -18,15 +18,6 @@ public class RuoYiApplication
     {
         // System.setProperty("spring.devtools.restart.enabled", "false");
         SpringApplication.run(RuoYiApplication.class, args);
-        System.out.println("(♥◠‿◠)ノ゙  若依启动成功   ლ(´ڡ`ლ)゙  \n" +
-                " .-------.       ____     __        \n" +
-                " |  _ _   \\      \\   \\   /  /    \n" +
-                " | ( ' )  |       \\  _. /  '       \n" +
-                " |(_ o _) /        _( )_ .'         \n" +
-                " | (_,_).' __  ___(_ o _)'          \n" +
-                " |  |\\ \\  |  ||   |(_,_)'         \n" +
-                " |  | \\ `'   /|   `-'  /           \n" +
-                " |  |  \\    /  \\      /           \n" +
-                " ''-'   `'-'    `-..-'              ");
+        System.out.println("模组启动成功");
     }
 }

+ 7 - 7
ruoyi-system/src/main/java/com/ruoyi/system/EchoThread.java

@@ -1,14 +1,15 @@
-package com.ruoyi.system;
+package com.ruoyi.tcp;
 
 import com.alibaba.fastjson.JSONObject;
-import java.io.PrintWriter;
+
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.PrintWriter;
 import java.net.Socket;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
-public class EchoThread implements Runnable{
+public class EchoThread{
     private Socket client;
     PrintWriter out = null;
     InputStream in = null;
@@ -18,9 +19,8 @@ public class EchoThread implements Runnable{
         this.client = client;
     }
 
-    @Override
     public void run() {
-        SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-DD hh:mm:ss");
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         try {
             out = new PrintWriter(client.getOutputStream(),true);
             in = client.getInputStream();
@@ -31,7 +31,7 @@ public class EchoThread implements Runnable{
                 inputLine+=new String(temp,0,length);
                 JSONObject object = JSONObject.parseObject(inputLine);
                 String st = object.get("ST").toString();
-                String serial = object.get("SERIAL").toString();
+                Integer serial = Integer.parseInt(object.get("SERIAL").toString());
                 if(".".equals(inputLine))
                 {
                     out.println("bye");
@@ -45,7 +45,7 @@ public class EchoThread implements Runnable{
                 JSONObject res = new JSONObject();
                 res.put("ST",st);
                 res.put("SERIAL",serial);
-                res.put("MARK","1");
+                res.put("MARK",1);
                 res.put("TM ", sdf.format(new Date()));
                 out.println(res);
             }

+ 10 - 11
ruoyi-system/src/main/java/com/ruoyi/system/TcpClientHandler.java

@@ -1,41 +1,40 @@
-package com.ruoyi.system;
+package com.ruoyi.tcp;
 
 
 
-import com.alibaba.fastjson.JSONObject;
+import com.ruoyi.common.utils.file.ImageUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.boot.CommandLineRunner;
-import org.springframework.context.annotation.Configuration;
 import org.springframework.stereotype.Component;
 
-import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintWriter;
 import java.net.ServerSocket;
 import java.net.Socket;
-import java.text.SimpleDateFormat;
-import java.util.Date;
+
 @Component
 public class TcpClientHandler  extends Thread implements CommandLineRunner {
 
+    private static final Logger log = LoggerFactory.getLogger(TcpClientHandler.class);
     private Socket clientSocket;
     private ServerSocket serverSocket;
     private PrintWriter out;
     private InputStream in;
-
-
+    private Integer port = 8802;
 
     @Override
     public void run(String... args) throws Exception
     {
 
         try{
-            ServerSocket server = new ServerSocket(8802);
+            ServerSocket server = new ServerSocket(port);
             Socket client = null;
             boolean flag = true;
             while(flag){
-                System.out.println("start...");
+                log.info("=============> TCP-Server is started with port:{} <=============",port);
                 client = server.accept();
-                new Thread(new EchoThread(client)).start();
+                new EchoThread(client).run();
             }
             client.close();
             server.close();