@Override
protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception {
if (frame instanceof TextWebSocketFrame) {
// Echos the same text
String text = ((TextWebSocketFrame) frame).text();
if (PING.equals(text)) {
ctx.writeAndFlush(new PingWebSocketFrame(Unpooled.wrappedBuffer(new byte[]{1, 2, 3, 4})));
return;
}
ctx.channel().writeAndFlush(new TextWebSocketFrame(text));
} else if (frame instanceof BinaryWebSocketFrame) {
ctx.channel().writeAndFlush(frame.retain());
} else if (frame instanceof CloseWebSocketFrame) {
ctx.close();
} else {
String message = "unsupported frame type: " + frame.getClass().getName();
throw new UnsupportedOperationException(message);
}
}
WebSocketRemoteServerFrameHandler.java 文件源码
java
阅读 25
收藏 0
点赞 0
评论 0
项目:carbon-transports
作者:
评论列表
文章目录