private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame msg) throws Exception {
if (log.isDebugEnabled())
log.debug("Received {} WebSocketFrame: {} from channel: {}", getTransportType().getName(), msg, ctx.channel());
if (msg instanceof CloseWebSocketFrame) {
sessionIdByChannel.remove(ctx.channel());
ChannelFuture f = ctx.writeAndFlush(msg);
f.addListener(ChannelFutureListener.CLOSE);
} else if (msg instanceof PingWebSocketFrame) {
ctx.writeAndFlush(new PongWebSocketFrame(msg.content()));
} else if (msg instanceof TextWebSocketFrame || msg instanceof BinaryWebSocketFrame){
Packet packet = PacketDecoder.decodePacket(msg.content());
packet.setTransportType(getTransportType());
String sessionId = sessionIdByChannel.get(ctx.channel());
packet.setSessionId(sessionId);
msg.release();
ctx.fireChannelRead(packet);
} else {
msg.release();
log.warn("{} frame type is not supported", msg.getClass().getName());
}
}
WebSocketHandler.java 文件源码
java
阅读 26
收藏 0
点赞 0
评论 0
项目:socketio
作者:
评论列表
文章目录