Exemplo n.º 1
0
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
      // Initiate 4 new streams
      int streamId = server ? 2 : 1;
      SpdySynStreamFrame spdySynStreamFrame = new DefaultSpdySynStreamFrame(streamId, 0, (byte) 0);
      spdySynStreamFrame.setLast(true);
      ctx.writeAndFlush(spdySynStreamFrame);
      spdySynStreamFrame.setStreamId(spdySynStreamFrame.getStreamId() + 2);
      ctx.writeAndFlush(spdySynStreamFrame);
      spdySynStreamFrame.setStreamId(spdySynStreamFrame.getStreamId() + 2);
      ctx.writeAndFlush(spdySynStreamFrame);
      spdySynStreamFrame.setStreamId(spdySynStreamFrame.getStreamId() + 2);
      ctx.writeAndFlush(spdySynStreamFrame);

      // Limit the number of concurrent streams to 1
      SpdySettingsFrame spdySettingsFrame = new DefaultSpdySettingsFrame();
      spdySettingsFrame.setValue(SpdySettingsFrame.SETTINGS_MAX_CONCURRENT_STREAMS, 1);
      ctx.writeAndFlush(spdySettingsFrame);
    }
Exemplo n.º 2
0
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
      if (msg instanceof SpdySynStreamFrame) {

        SpdySynStreamFrame spdySynStreamFrame = (SpdySynStreamFrame) msg;
        if (!spdySynStreamFrame.isUnidirectional()) {
          int streamId = spdySynStreamFrame.getStreamId();
          SpdySynReplyFrame spdySynReplyFrame = new DefaultSpdySynReplyFrame(streamId);
          spdySynReplyFrame.setLast(spdySynStreamFrame.isLast());
          for (Map.Entry<String, String> entry : spdySynStreamFrame.headers()) {
            spdySynReplyFrame.headers().add(entry.getKey(), entry.getValue());
          }

          ctx.writeAndFlush(spdySynReplyFrame);
        }
        return;
      }

      if (msg instanceof SpdySynReplyFrame) {
        return;
      }

      if (msg instanceof SpdyDataFrame
          || msg instanceof SpdyPingFrame
          || msg instanceof SpdyHeadersFrame) {

        ctx.writeAndFlush(msg);
        return;
      }

      if (msg instanceof SpdySettingsFrame) {
        SpdySettingsFrame spdySettingsFrame = (SpdySettingsFrame) msg;
        if (spdySettingsFrame.isSet(closeSignal)) {
          ctx.close();
        }
      }
    }
Exemplo n.º 3
0
 static {
   closeMessage.setValue(closeSignal, 0);
 }