WebSocketService использование

This commit is contained in:
Gravit 2018-10-01 15:11:56 +07:00
parent b42d3d6a08
commit 3daabe584f
2 changed files with 2 additions and 4 deletions

View file

@ -23,6 +23,7 @@
public class WebSocketFrameHandler extends SimpleChannelInboundHandler<WebSocketFrame> {
public static final ChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
public static Gson gson;
public WebSocketService service = new WebSocketService(LaunchServer.server,gson);
public static LaunchServer server;
public static GsonBuilder builder = new GsonBuilder();
@ -40,9 +41,7 @@ public void channelActive(ChannelHandlerContext ctx) {
protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception {
// ping and pong frames already handled
if (frame instanceof TextWebSocketFrame) {
String request = ((TextWebSocketFrame) frame).text();
JsonResponse response = gson.fromJson(request, JsonResponse.class);
response.execute(ctx, frame);
service.process(ctx, (TextWebSocketFrame) frame);
} else {
String message = "unsupported frame type: " + frame.getClass().getName();
throw new UnsupportedOperationException(message);

View file

@ -22,7 +22,6 @@ public String getType() {
@Override
public void execute(WebSocketService service,ChannelHandlerContext ctx) {
LogHelper.info("Echo: %s",echo);
ctx.channel().writeAndFlush(new TextWebSocketFrame(WebSocketFrameHandler.gson.toJson(new Result(echo))));
service.sendObject(ctx,new Result(echo));
}
public class Result