jiazx0107@163.com
2023-05-17 620eab6cca2bc9ef9ea6d3067a0a5ba1deadbd1c
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.ld.igds.io.sample.lt;
 
import com.ld.igds.util.BytesUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
 
import java.net.InetSocketAddress;
 
/**
 * Handles a client-side channel.
 */
 
public class ClientHandler extends SimpleChannelInboundHandler<Object> {
    private final InternalLogger log = InternalLoggerFactory.getInstance(this
            .getClass());
    @Override
    public void channelActive(ChannelHandlerContext ctx) {
        InetSocketAddress insocket = (InetSocketAddress) ctx.channel()
                .remoteAddress();
        log.info("扦样机成功连接,IP={},port={}", insocket.getAddress()
                .getHostAddress(), insocket.getPort());
        if(LtCheckClientEngine.CHECK_MAC.get( insocket.getAddress().getHostAddress()) == null ){
            LtCheckClientEngine.CHECK_MAC.put( insocket.getAddress().getHostAddress(),new LtCHeckMac());
        }
        LtCheckClientEngine.CHECK_MAC.get( insocket.getAddress().getHostAddress()).setSerStart(true);
    }
 
    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        super.channelInactive(ctx);
 
        InetSocketAddress insocket = (InetSocketAddress) ctx.channel()
                .remoteAddress();
 
        log.info("扦样机断开连接,IP={},port={}", insocket.getAddress()
                .getHostAddress(), insocket.getPort());
        if(LtCheckClientEngine.CHECK_MAC.get( insocket.getAddress().getHostAddress()) == null ){
            LtCheckClientEngine.CHECK_MAC.put( insocket.getAddress().getHostAddress(),new LtCHeckMac());
        }
        LtCheckClientEngine.CHECK_MAC.get( insocket.getAddress().getHostAddress()).setSerStart(false);
 
    }
 
    @Override
    public void channelRead0(ChannelHandlerContext ctx, Object msg)
            throws Exception {
        byte[] bytes = (byte[]) msg;
 
        log.info("扦样机终端返回信息=" + BytesUtil.bytesToString(bytes));
 
        InetSocketAddress insocket = (InetSocketAddress) ctx.channel()
                .remoteAddress();
 
        CheckAnalysis.analysisInfo(insocket.getAddress().getHostAddress(),
                insocket.getPort(), bytes);
    }
 
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        ctx.close();
    }
 
}