vince
2024-12-13 d3e48589ea2719cdde41b87fc1ad80f4ee509bac
src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerEngine.java
@@ -1,5 +1,7 @@
package com.fzzy.protocol.bhzn.v0.server;
import com.fzzy.api.utils.BytesUtil;
import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerUtils;
import com.fzzy.protocol.fzzy.server.ServerUtils;
import com.ld.io.api.*;
import com.ld.io.netty.NettyServer;
@@ -15,7 +17,7 @@
public class BhznGrainV0ServerEngine {
    public static final Integer PORT = 19302;
    public static final Integer PORT = 19303;
    public static NettyServer ioServer = null;
@@ -39,8 +41,13 @@
        }
        //确认结尾标志-没有固定结束符号
        //确认结尾标志
        //ioServerOption.setDelimiter(BhznGrainV2ServerUtils.MSG_END.getBytes());
        ioServerOption.setSplitDecoderType(SplitByteDecoderType.NO_LIMIT);
//        ioServerOption.setDelimiter(BhznGrainV2ServerUtils.MSG_END.getBytes());
//        ioServerOption.setSplitDecoderType(SplitByteDecoderType.DELIMITER_SYMBOL);
        // 配置系统心跳间隔
        ioServerOption.setReaderIdleTime(5 * 60);
@@ -64,28 +71,17 @@
    }
    /**
     * 发送信息
     *
     * @param ip
     * @param port
     * @param msg
     * @return
     * 直接使用内存的Session执行
     */
    public static InvokeResult push(String ip, int port, byte[] msg) {
        IoSessionQuery sessionFactory = ioServer.getSessionQuery();
        List<IoSession> sessions = sessionFactory.getAllSession();
        IoSession session = null;
        for (IoSession ioSession : sessions) {
            if (ServerUtils.getServerKey(ip, port).equals(ioSession.getBusinessKey())) {
                session = ioSession;
                break;
            }
        }
    public static InvokeResult pushByMin(String hexStr) {
        IoSession session = BhznGrainV0ServerUtils.getSession();
        if (null == session) {
            return InvokeResult.CHANNEL_CLOSED;
        }
        byte[] msg = BytesUtil.hexStrToBytes(hexStr);
        return session.invoke(msg);
    }
}