sgj
2026-03-23 fff68633c2fb6aad6b6b42077bb8d5833b92d4d2
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
package com.fzzy.igds.iot.server;
 
 
import com.fzzy.igds.io.notify.ServerNotifyInvoker;
import com.fzzy.igds.utils.SpringUtil;
import com.ld.io.api.IoSession;
import com.ld.io.api.IoSessionListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
/**
 * @Description
 * @Author CZT
 * @Date 2025/11/11 18:09
 */
@Slf4j
@Service
public class IotSessionListener implements IoSessionListener {
    private ServerNotifyInvoker serverNotifyInvoker;
 
    @Override
    public void onCreate(IoSession session) {
 
        log.info("++++新建连接++++-IP={},PORT={}", session.getAddress(), session.getPort());
 
        // 添加自定义业务ID
        session.setBusinessKey(ServerUtils.getServerKey(session.getAddress(), session.getPort()));
    }
 
    @Override
    public void onDestroy(IoSession session) {
        log.info("----连接断开-----IP={},PORT={}", session.getAddress(), session.getPort());
 
        if (null == serverNotifyInvoker) {
            serverNotifyInvoker = SpringUtil.getBean(ServerNotifyInvoker.class);
        }
        serverNotifyInvoker.connectDestory(session.getBusinessKey(),
                session.getAddress(), session.getPort());
    }
}