| | |
| | | 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; |
| | |
| | | |
| | | public class BhznGrainV0ServerEngine { |
| | | |
| | | public static final Integer PORT = 19302; |
| | | public static final Integer PORT = 19303; |
| | | |
| | | public static NettyServer ioServer = null; |
| | | |
| | |
| | | } |
| | | |
| | | //确认结尾标志-没有固定结束符号 |
| | | ioServerOption.setSplitDecoderType(SplitByteDecoderType.NO_LIMIT); |
| | | |
| | | //确认结尾标志 |
| | | //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); |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 发送信息 |
| | | * |
| | | * @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); |
| | | } |
| | | |
| | | |
| | | } |