liurunyu
2024-08-15 f7e731bdc2fce4445c0d22993134c6c2b07d207b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.ruoyi.netty;
 
 
import com.ruoyi.common.utils.netty.IPUtil;
import com.ruoyi.netty.communication.TcpServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
 
/**
 * @author 86175
 */
@Component
@Order(1)
@Slf4j
 
public class InitService implements ApplicationRunner {
 
 
    @Override
    public void run(ApplicationArguments args) {
        log.info("---------------正在初始化程序请稍后------------------");
        startTCPServer();
    }
 
    /**
     * 启动TCP服务
     */
    private void startTCPServer() {
        String iP = IPUtil.getLocalIP();
        Integer port = 6001;
        log.info("端口为:" + port + "IP地址:" + iP);
        try {
            new TcpServer().init(iP, port);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
 
}