mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
Начало нового протокола
This commit is contained in:
parent
4e739a74b5
commit
5cbc81476f
1 changed files with 19 additions and 15 deletions
|
@ -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<WebSocketFrame> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue