From 5cbc81476f714cedbf83bf3891651d04719edc55 Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 21 Sep 2018 21:36:23 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE=20=D0=BF=D1=80=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D0=BA=D0=BE=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../websocket/WebSocketFrameHandler.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java index e250e18b..d4320a4b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java @@ -1,27 +1,31 @@ package ru.gravit.launchserver.socket.websocket; -import io.netty.channel.ChannelHandler; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufInputStream; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import io.netty.channel.group.ChannelGroup; +import io.netty.channel.group.DefaultChannelGroup; import io.netty.handler.codec.http.websocketx.WebSocketFrame; -import io.netty.util.concurrent.EventExecutorGroup; - -import java.util.Locale; +import io.netty.util.concurrent.GlobalEventExecutor; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.LogHelper; public class WebSocketFrameHandler extends SimpleChannelInboundHandler { - + static final ChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); + @Override + public void channelActive(ChannelHandlerContext ctx) { + LogHelper.debug("New client %s", IOHelper.getIP(ctx.channel().remoteAddress())); + channels.add(ctx.channel()); + } @Override - protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception { // ping and pong frames already handled - if (frame instanceof TextWebSocketFrame) { - // Send the uppercase string back. - String request = ((TextWebSocketFrame) frame).text(); - ctx.channel().writeAndFlush(new TextWebSocketFrame(request.toUpperCase(Locale.US))); - } else { - String message = "unsupported frame type: " + frame.getClass().getName(); - throw new UnsupportedOperationException(message); - } + ByteBuf buf = frame.content(); + ByteBufInputStream input = new ByteBufInputStream(buf); + long handshake = input.readLong(); + long connection_flags = input.readLong(); + long type = input.readInt(); + LogHelper.debug("MessageHead: handshake %dl, flags %dl, type %d", handshake,connection_flags,type); } }