コード例 #1
0
  private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
    if (logger.isLoggable(Level.FINE)) {
      logger.fine(
          String.format(
              "Channel %s received %s",
              ctx.channel().hashCode(), frame.getClass().getSimpleName()));
    }

    if (frame instanceof CloseWebSocketFrame) {
      handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame);
    } else if (frame instanceof PingWebSocketFrame) {
      ctx.write(new PongWebSocketFrame(frame.isFinalFragment(), frame.rsv(), frame.content()));
    } else if (frame instanceof TextWebSocketFrame) {
      ctx.write(frame);
    } else if (frame instanceof BinaryWebSocketFrame) {
      ctx.write(frame);
    } else if (frame instanceof ContinuationWebSocketFrame) {
      ctx.write(frame);
    } else if (frame instanceof PongWebSocketFrame) {
      frame.release();
      // Ignore
    } else {
      throw new UnsupportedOperationException(
          String.format("%s frame types not supported", frame.getClass().getName()));
    }
  }
コード例 #2
0
  private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
    logger.debug(
        String.format(
            "Channel %s received %s", ctx.getChannel().getId(), frame.getClass().getSimpleName()));

    if (frame instanceof CloseWebSocketFrame) {
      this.handshaker.performClosingHandshake(ctx, (CloseWebSocketFrame) frame);
    } else if (frame instanceof PingWebSocketFrame) {
      ctx.getChannel()
          .write(
              new PongWebSocketFrame(
                  frame.isFinalFragment(), frame.getRsv(), frame.getBinaryData()));
    } else if (frame instanceof TextWebSocketFrame) {
      // String text = ((TextWebSocketFrame) frame).getText();
      ctx.getChannel()
          .write(
              new TextWebSocketFrame(
                  frame.isFinalFragment(), frame.getRsv(), frame.getBinaryData()));
    } else if (frame instanceof BinaryWebSocketFrame) {
      ctx.getChannel()
          .write(
              new BinaryWebSocketFrame(
                  frame.isFinalFragment(), frame.getRsv(), frame.getBinaryData()));
    } else if (frame instanceof ContinuationWebSocketFrame) {
      ctx.getChannel()
          .write(
              new ContinuationWebSocketFrame(
                  frame.isFinalFragment(), frame.getRsv(), frame.getBinaryData()));
    } else if (frame instanceof PongWebSocketFrame) {
      // Ignore
    } else {
      throw new UnsupportedOperationException(
          String.format("%s frame types not supported", frame.getClass().getName()));
    }
  }
コード例 #3
0
  private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {

    System.out.println("pre1:" + frame);

    // Check for closing frame
    if (frame instanceof CloseWebSocketFrame) {
      handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
      return;
    }
    if (frame instanceof PingWebSocketFrame) {
      ctx.channel().write(new PongWebSocketFrame(frame.content().retain()));
      return;
    }
    if (!(frame instanceof TextWebSocketFrame)) {
      throw new UnsupportedOperationException(
          String.format("%s frame types not supported", frame.getClass().getName()));
    }

    WebsocketMessageHandlerI websocketMessageHandler = new WebSocketMessageHander(ctx, channels);
    // Send the uppercase string back.

    String requestRaw = ((TextWebSocketFrame) frame).text();

    websocketMessageHandler.handleMessage(requestRaw);
  }
コード例 #4
0
 private ChannelFuture handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
   // Check for closing frame
   if (frame instanceof CloseWebSocketFrame) {
     return Handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
   } else if (frame instanceof PingWebSocketFrame) {
     return ctx.channel().write(new PongWebSocketFrame(frame.content().retain()));
   } else if (frame instanceof TextWebSocketFrame) {
     TextWebSocketFrame textFrame = (TextWebSocketFrame) frame;
     String messageText = textFrame.text();
     return handleTextMessage(messageText);
   } else {
     throw new UnsupportedOperationException(
         String.format("%s frame types not supported", frame.getClass().getName()));
   }
 }
コード例 #5
0
  private void handlerWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {

    // �ж��Ƿ�ر���·��ָ��
    if (frame instanceof CloseWebSocketFrame) {
      handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
    }

    // �ж��Ƿ�ping��Ϣ
    if (frame instanceof PingWebSocketFrame) {
      ctx.channel().write(new PongWebSocketFrame(frame.content().retain()));
      return;
    }

    // �����̽�֧���ı���Ϣ����֧�ֶ�������Ϣ
    if (!(frame instanceof TextWebSocketFrame)) {

      System.out.println("�����̽�֧���ı���Ϣ����֧�ֶ�������Ϣ");

      throw new UnsupportedOperationException(
          String.format("%s frame types not supported", frame.getClass().getName()));
    }

    // ����Ӧ����Ϣ
    String request = ((TextWebSocketFrame) frame).text();

    System.out.println("������յ���" + request);

    if (logger.isLoggable(Level.FINE)) {
      logger.fine(String.format("%s received %s", ctx.channel(), request));
    }

    TextWebSocketFrame tws =
        new TextWebSocketFrame(new Date().toString() + ctx.channel().id() + "��" + request);

    // Ⱥ��
    Global.group.writeAndFlush(tws);

    // ���ء�˭���ķ���˭��
    // ctx.channel().writeAndFlush(tws);

  }
コード例 #6
0
  private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {

    // Check for closing frame
    if (frame instanceof CloseWebSocketFrame) {
      handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
      return;
    }
    if (frame instanceof PingWebSocketFrame) {
      ctx.channel().write(new PongWebSocketFrame(frame.content().retain()));
      return;
    }
    if (!(frame instanceof TextWebSocketFrame)) {
      throw new UnsupportedOperationException(
          String.format("%s frame types not supported", frame.getClass().getName()));
    }

    // Send the uppercase string back.
    String request = ((TextWebSocketFrame) frame).text();
    System.err.printf("%s received %s%n", ctx.channel(), request);
    ctx.channel().write(new TextWebSocketFrame(request.toUpperCase()));
  }