7 Star 31 Fork 15

huan1993/netty-study

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
BinaryWebSocketFrameHandler.java 1.00 KB
一键复制 编辑 原始数据 按行查看 历史
package com.huan.netty.websocket;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 处理二进制消息
*
* @author huan.fu
* @date 2018/11/8 - 14:37
*/
public class BinaryWebSocketFrameHandler extends SimpleChannelInboundHandler<BinaryWebSocketFrame> {
private static final Logger log = LoggerFactory.getLogger(BinaryWebSocketFrameHandler.class);
@Override
protected void channelRead0(ChannelHandlerContext ctx, BinaryWebSocketFrame msg) throws InterruptedException {
log.info("服务器接收到二进制消息,消息长度:[{}]", msg.content().capacity());
ByteBuf byteBuf = Unpooled.directBuffer(msg.content().capacity());
byteBuf.writeBytes(msg.content());
ctx.writeAndFlush(new BinaryWebSocketFrame(byteBuf));
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/huan1993/netty-study.git
git@gitee.com:huan1993/netty-study.git
huan1993
netty-study
netty-study
master

搜索帮助