czt
2024-07-13 bd01ba57ed8526a0ee94a50e1f52034251bb54f6
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
package com.ld.igds.protocol.iot.height.server;
 
 
import com.ld.igds.io.notify.ServerNotifyInvoker;
import com.ld.igds.util.SpringUtil;
import com.ld.io.api.IoSession;
import com.ld.io.api.IoSessionListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@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());
    }
}