Skip to content

Commit

Permalink
fix websocket frame release again. (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
fzdwx committed Jun 24, 2022
1 parent b53f34e commit 09337dd
Showing 1 changed file with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,25 @@ public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cau

@Override
protected void channelRead0(final ChannelHandlerContext ctx, final WebSocketFrame msg) throws Exception {
try {
if (msg instanceof TextWebSocketFrame) {
listener.onText(session, ((TextWebSocketFrame) msg).text());
} else {
if (msg instanceof TextWebSocketFrame) {
listener.onText(session, ((TextWebSocketFrame) msg).text());
} else {

if (msg instanceof BinaryWebSocketFrame) {
listener.onBinary(session, Netty.readBytes(msg.content()));
} else if (msg instanceof PingWebSocketFrame) {
listener.onPing(Netty.readBytes(msg.content()));
} else if (msg instanceof PongWebSocketFrame) {
listener.onPong(Netty.readBytes(msg.content()));
}
if (msg instanceof BinaryWebSocketFrame) {
listener.onBinary(session, Netty.readBytes(msg.content()));
} else if (msg instanceof PingWebSocketFrame) {
listener.onPing(Netty.readBytes(msg.content()));
} else if (msg instanceof PongWebSocketFrame) {
listener.onPong(Netty.readBytes(msg.content()));
}

// TODO
// 1.是否需要让服务端手动处理 close frame
// 2.客户端是否会通过close frame 来传递数据?
if (msg instanceof CloseWebSocketFrame) {
listener.onclose(session);
ctx.channel().close();
}
// TODO
// 1.是否需要让服务端手动处理 close frame
// 2.客户端是否会通过close frame 来传递数据?
if (msg instanceof CloseWebSocketFrame) {
listener.onclose(session);
ctx.channel().close();
}
} finally {
msg.release();
}
}
}

0 comments on commit 09337dd

Please sign in to comment.