MrShi
2025-09-15 856f526f823f5dad88c28657d82f971ff66afb1e
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
package org.yzh;
 
import io.github.yezhihao.netmc.NettyConfig;
import io.github.yezhihao.netmc.Server;
import io.github.yezhihao.netmc.core.DefaultHandlerMapping;
import io.github.yezhihao.netmc.handler.DispatcherHandler;
import io.github.yezhihao.netmc.session.SessionListener;
import io.github.yezhihao.netmc.session.SessionManager;
import org.apache.logging.log4j.Level;
import org.yzh.protocol.codec.JTMessageAdapter;
import org.yzh.web.endpoint.JTHandlerInterceptor;
 
/**
 * 不依赖spring,快速启动netty服务
 */
public class QuickStart {
    public static final JTMessageAdapter messageAdapter = new JTMessageAdapter("org.yzh.client");
//    public static final JTMessageAdapter messageAdapter = new JTMessageAdapter("org.yzh.protocol");
    public static final DefaultHandlerMapping handlerMapping = new DefaultHandlerMapping("org.yzh.client");
//    public static final DefaultHandlerMapping handlerMapping = new DefaultHandlerMapping("org.yzh.web.endpoint");
    public static final JTHandlerInterceptor handlerInterceptor = new JTHandlerInterceptor();
    public static final SessionManager sessionManager = new SessionManager(new SessionListener() {
    });
 
    public static final int port = 7611;
 
    public static void main(String[] args) {
//        LogUtils.setLevel(Level.WARN);
        DispatcherHandler.STOPWATCH = true;
 
        Server tcpServer = new NettyConfig.Builder()
                .setPort(port)
                .setMaxFrameLength(2 + 21 + 1023 * 2 + 1 + 2)
//                .setMaxFrameLength(4096)
                .setDelimiters(new byte[][]{{0x7e}})
                .setDecoder(messageAdapter)
                .setEncoder(messageAdapter)
                .setHandlerMapping(handlerMapping)
                .setHandlerInterceptor(handlerInterceptor)
                .setSessionManager(sessionManager)
                .setName("808-TCP")
                .build();
        tcpServer.start();
 
     /*   Server udpServer = new NettyConfig.Builder()
                .setPort(port)
                .setDecoder(messageAdapter)
                .setEncoder(messageAdapter)
                .setHandlerMapping(handlerMapping)
                .setHandlerInterceptor(handlerInterceptor)
                .setSessionManager(sessionManager)
                .setEnableUDP(true)
                .setName("808-UDP")
                .build();
        udpServer.start();*/
    }
}