Search in sources :

Example 1 with SMGPMessageCodec

use of com.zx.sms.codec.smgp.codec.SMGPMessageCodec in project SMSGate by Lihuanghe.

the class SMGPSessionLoginManager method changeProtoVersion.

@Override
protected void changeProtoVersion(ChannelHandlerContext ctx, EndpointEntity entity, Object msg) throws Exception {
    SMGPLoginMessage message = (SMGPLoginMessage) msg;
    final short clientVersion = message.getVersion();
    short aim_ver = clientVersion;
    if (entity != null) {
        SMGPServerChildEndpointEntity childentity = (SMGPServerChildEndpointEntity) entity;
        // 以服务端配置的版本为准
        aim_ver = childentity.getClientVersion();
        // 发送ConnectRequest里的Version跟配置的不同
        if (aim_ver != clientVersion) {
            logger.warn("receive version code {} ,expected version is {} .I would use version {}", clientVersion, aim_ver, aim_ver);
        }
    }
    // 默认的是3.0的协议,如果不是则要更换解析器版本
    if ((byte) 0x30 != aim_ver) {
        // 以配置的协议版本为准
        // 更换协议解析器
        logger.info("changeCodec to version:{}", aim_ver);
        ctx.pipeline().replace(GlobalConstance.codecName, GlobalConstance.codecName, new SMGPMessageCodec(aim_ver));
    }
}
Also used : SMGPMessageCodec(com.zx.sms.codec.smgp.codec.SMGPMessageCodec) SMGPLoginMessage(com.zx.sms.codec.smgp.msg.SMGPLoginMessage) SMGPServerChildEndpointEntity(com.zx.sms.connect.manager.smgp.SMGPServerChildEndpointEntity)

Example 2 with SMGPMessageCodec

use of com.zx.sms.codec.smgp.codec.SMGPMessageCodec in project SMSGate by Lihuanghe.

the class SMGPCodecChannelInitializer method initChannel.

@Override
protected void initChannel(Channel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    pipeline.addBefore(pipeName(), "FrameDecoder", new LengthFieldBasedFrameDecoder(4 * 1024, 0, 4, -4, 0, true));
    pipeline.addBefore(pipeName(), GlobalConstance.codecName, new SMGPMessageCodec(version));
}
Also used : SMGPMessageCodec(com.zx.sms.codec.smgp.codec.SMGPMessageCodec) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

SMGPMessageCodec (com.zx.sms.codec.smgp.codec.SMGPMessageCodec)2 SMGPLoginMessage (com.zx.sms.codec.smgp.msg.SMGPLoginMessage)1 SMGPServerChildEndpointEntity (com.zx.sms.connect.manager.smgp.SMGPServerChildEndpointEntity)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 LengthFieldBasedFrameDecoder (io.netty.handler.codec.LengthFieldBasedFrameDecoder)1