18 Star 128 Fork 54

baolinking/物联网关

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
MasterChannelInitializer.java 1.05 KB
一键复制 编辑 原始数据 按行查看 历史
baolinking 提交于 6年前 . link
/**
*
*/
package masterpro;
import java.util.concurrent.TimeUnit;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.protobuf.ProtobufDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.handler.timeout.IdleStateHandler;
import protobuf.MasterMessage;
/**
* @Description: Filter
* @version: v1.0.0
* @author: wbl
* @date: 2019年9月3日 下午5:01:10
*/
public class MasterChannelInitializer extends ChannelInitializer<SocketChannel>{
int masterid = 0;
public MasterChannelInitializer(int masterid){
this.masterid = masterid;
}
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new IdleStateHandler(0, 10, 0, TimeUnit.SECONDS));
ch.pipeline().addLast("decoder", new ProtobufDecoder(MasterMessage.Message.getDefaultInstance()));
ch.pipeline().addLast(new StringEncoder());//组码发给客户端
ch.pipeline().addLast(new MasterClientHandler(masterid));
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/baolinking/gateway.git
git@gitee.com:baolinking/gateway.git
baolinking
gateway
物联网关
master

搜索帮助

371d5123 14472233 46e8bd33 14472233