当前位置: 首页>>代码示例>>Java>>正文


Java CloseWebSocketFrame类代码示例

本文整理汇总了Java中io.netty.handler.codec.http.websocketx.CloseWebSocketFrame的典型用法代码示例。如果您正苦于以下问题:Java CloseWebSocketFrame类的具体用法?Java CloseWebSocketFrame怎么用?Java CloseWebSocketFrame使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CloseWebSocketFrame类属于io.netty.handler.codec.http.websocketx包,在下文中一共展示了CloseWebSocketFrame类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleWebSocketFrame

import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; //导入依赖的package包/类
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
    if (logger.isLoggable(Level.FINE)) {
        logger.fine(String.format(
                "Channel %s received %s", ctx.channel().hashCode(), StringUtil.simpleClassName(frame)));
    }

    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()), ctx.voidPromise());
    } else if (frame instanceof TextWebSocketFrame) {
        ctx.write(frame, ctx.voidPromise());
    } else if (frame instanceof BinaryWebSocketFrame) {
        ctx.write(frame, ctx.voidPromise());
    } else if (frame instanceof ContinuationWebSocketFrame) {
        ctx.write(frame, ctx.voidPromise());
    } else if (frame instanceof PongWebSocketFrame) {
        frame.release();
        // Ignore
    } else {
        throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass()
                .getName()));
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:25,代码来源:AutobahnServerHandler.java

示例2: channelRead0

import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; //导入依赖的package包/类
@Override
public void channelRead0(ChannelHandlerContext context, Object message) throws Exception {
  Channel channel = context.channel();
  if (message instanceof FullHttpResponse) {
    checkState(!handshaker.isHandshakeComplete());
    try {
      handshaker.finishHandshake(channel, (FullHttpResponse) message);
      delegate.onOpen();
    } catch (WebSocketHandshakeException e) {
      delegate.onError(e);
    }
  } else if (message instanceof TextWebSocketFrame) {
    delegate.onMessage(((TextWebSocketFrame) message).text());
  } else {
    checkState(message instanceof CloseWebSocketFrame);
    delegate.onClose();
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:19,代码来源:NettyWebSocketClient.java

示例3: handlerWebSocketFrame

import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; //导入依赖的package包/类
private void handlerWebSocketFrame(ChannelHandlerContext ctx,
		WebSocketFrame frame) {
	// 判断是否关闭链路的指令
	if (frame instanceof CloseWebSocketFrame) {
		socketServerHandshaker.close(ctx.channel(),
				(CloseWebSocketFrame) frame.retain());
	}
	// 判断是否ping消息
	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()));
	}
	// 返回应答消息
	String request = ((TextWebSocketFrame) frame).text();
	System.out.println("服务端收到:" + request);
	TextWebSocketFrame tws = new TextWebSocketFrame(new Date().toString()
			+ ctx.channel().id() + ":" + request);
	// 群发
	group.writeAndFlush(tws);
}
 
开发者ID:hdcuican,项目名称:java_learn,代码行数:27,代码来源:WebSocketServerHandler.java

示例4: testCreateSubscriptionWithMissingSessionId

import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; //导入依赖的package包/类
@Test
public void testCreateSubscriptionWithMissingSessionId() throws Exception {
    decoder = new WebSocketRequestDecoder(config);
    // @formatter:off
    String request = "{ "+ 
      "\"operation\" : \"create\", " +
      "\"subscriptionId\" : \"1234\"" + 
    " }";
    // @formatter:on
    TextWebSocketFrame frame = new TextWebSocketFrame();
    frame.content().writeBytes(request.getBytes(StandardCharsets.UTF_8));
    decoder.decode(ctx, frame, results);
    Assert.assertNotNull(ctx.msg);
    Assert.assertEquals(CloseWebSocketFrame.class, ctx.msg.getClass());
    Assert.assertEquals(1008, ((CloseWebSocketFrame) ctx.msg).statusCode());
    Assert.assertEquals("User must log in", ((CloseWebSocketFrame) ctx.msg).reasonText());
}
 
开发者ID:NationalSecurityAgency,项目名称:timely,代码行数:18,代码来源:WebSocketRequestDecoderTest.java

示例5: testCreateSubscriptionWithInvalidSessionIdAndNonAnonymousAccess

import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; //导入依赖的package包/类
@Test
public void testCreateSubscriptionWithInvalidSessionIdAndNonAnonymousAccess() throws Exception {
    ctx.channel().attr(SubscriptionRegistry.SESSION_ID_ATTR)
            .set(URLEncoder.encode(UUID.randomUUID().toString(), StandardCharsets.UTF_8.name()));
    decoder = new WebSocketRequestDecoder(config);
    // @formatter:off
    String request = "{ "+ 
      "\"operation\" : \"create\", " +
      "\"subscriptionId\" : \"1234\"" + 
    " }";
    // @formatter:on
    TextWebSocketFrame frame = new TextWebSocketFrame();
    frame.content().writeBytes(request.getBytes(StandardCharsets.UTF_8));
    decoder.decode(ctx, frame, results);
    Assert.assertNotNull(ctx.msg);
    Assert.assertEquals(CloseWebSocketFrame.class, ctx.msg.getClass());
    Assert.assertEquals(1008, ((CloseWebSocketFrame) ctx.msg).statusCode());
    Assert.assertEquals("User must log in", ((CloseWebSocketFrame) ctx.msg).reasonText());
}
 
开发者ID:NationalSecurityAgency,项目名称:timely,代码行数:20,代码来源:WebSocketRequestDecoderTest.java

示例6: handleFrame

import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; //导入依赖的package包/类
private void handleFrame(Channel channel, WebSocketFrame frame, WebSocketUpgradeHandler handler, NettyWebSocket webSocket) throws Exception {
    if (frame instanceof CloseWebSocketFrame) {
        Channels.setDiscard(channel);
        CloseWebSocketFrame closeFrame = (CloseWebSocketFrame) frame;
        webSocket.onClose(closeFrame.statusCode(), closeFrame.reasonText());
    } else {
        ByteBuf buf = frame.content();
        if (buf != null && buf.readableBytes() > 0) {
            HttpResponseBodyPart part = config.getResponseBodyPartFactory().newResponseBodyPart(buf, frame.isFinalFragment());
            handler.onBodyPartReceived(part);

            if (frame instanceof BinaryWebSocketFrame) {
                webSocket.onBinaryFragment(part);
            } else if (frame instanceof TextWebSocketFrame) {
                webSocket.onTextFragment(part);
            } else if (frame instanceof PingWebSocketFrame) {
                webSocket.onPing(part);
            } else if (frame instanceof PongWebSocketFrame) {
                webSocket.onPong(part);
            }
        }
    }
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:24,代码来源:WebSocketHandler.java

示例7: onInboundNext

import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; //导入依赖的package包/类
@Override
public void onInboundNext(ChannelHandlerContext ctx, Object frame) {
	if (frame instanceof CloseWebSocketFrame && ((CloseWebSocketFrame) frame).isFinalFragment()) {
		if (log.isDebugEnabled()) {
			log.debug("CloseWebSocketFrame detected. Closing Websocket");
		}
		CloseWebSocketFrame close = (CloseWebSocketFrame) frame;
		sendClose(new CloseWebSocketFrame(true,
				close.rsv(),
				close.content()), f -> onHandlerTerminate());
		return;
	}
	if (frame instanceof PingWebSocketFrame) {
		ctx.writeAndFlush(new PongWebSocketFrame(((PingWebSocketFrame) frame).content()));
		ctx.read();
		return;
	}
	super.onInboundNext(ctx, frame);
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:20,代码来源:HttpServerWSOperations.java

示例8: decodeWebSocketFrame

import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; //导入依赖的package包/类
private Message decodeWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
	// Check for closing frame
	if (frame instanceof CloseWebSocketFrame) {
		handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
		return null;
	}
	
	if (frame instanceof PingWebSocketFrame) {
		ctx.write(new PongWebSocketFrame(frame.content().retain()));
		return null;
	}
	
	if (frame instanceof TextWebSocketFrame) {
		TextWebSocketFrame textFrame = (TextWebSocketFrame) frame;
		return parseMessage(textFrame.content());
	}
	
	if (frame instanceof BinaryWebSocketFrame) {
		BinaryWebSocketFrame binFrame = (BinaryWebSocketFrame) frame;
		return parseMessage(binFrame.content());
	}
	
	log.warn("Message format error: " + frame); 
	return null;
}
 
开发者ID:rushmore,项目名称:zbus,代码行数:26,代码来源:MessageCodec.java

示例9: handleWebSocketFrame

import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; //导入依赖的package包/类
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.write(new PongWebSocketFrame(frame.content().retain()));
            return;
        }
        if (frame instanceof TextWebSocketFrame) {
            // Echo the frame
            ctx.write(frame.retain());
            return;
        }
        if (frame instanceof BinaryWebSocketFrame) {
            // Echo the frame
            ctx.write(frame.retain());
            return;
        }
    }
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:23,代码来源:WebSocketServerHandler.java

示例10: handleWebSocketFrame

import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; //导入依赖的package包/类
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
	// Check for closing frame
	if (frame instanceof CloseWebSocketFrame) {
		addTraceForFrame(frame, "close");
		handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
		return;
	}
	if (frame instanceof PingWebSocketFrame) {
		addTraceForFrame(frame, "ping");
		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()));
	}

	// todo [om] think about BinaryWebsocketFrame

	handleTextWebSocketFrameInternal((TextWebSocketFrame) frame, ctx);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:22,代码来源:WebsocketSinkServerHandler.java

示例11: handleWebSocketFrame

import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; //导入依赖的package包/类
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()));
    }
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:22,代码来源:WebSocketServerHandler.java

示例12: accept

import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; //导入依赖的package包/类
@Override
public void accept(ChannelHandlerContext ctx, WebSocketFrame frame) {
	if (frame instanceof CloseWebSocketFrame) {
		handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
		endpoint.releaseReferences();
		endpoint.onClose();
		return;
	}
	
	if (frame instanceof PingWebSocketFrame) {
		ctx.channel().write(new PongWebSocketFrame(frame.content().retain()));
		return;
	}
	
	if (frame instanceof TextWebSocketFrame) {
		endpoint.onMessage(((TextWebSocketFrame) frame).text());
		return;
	}
	
	throw new UnsupportedOperationException(String.format("Unsupported websocket frame of type %s", frame.getClass().getName()));
}
 
开发者ID:lukasdietrich,项目名称:lambdatra,代码行数:22,代码来源:WsAdapter.java

示例13: handlerWebSocketFrame

import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; //导入依赖的package包/类
private void handlerWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
	// 判断是否关闭链路的指令
	if (frame instanceof CloseWebSocketFrame) {
		handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
		return;
	}
	// 判断是否ping消息
	if (frame instanceof PingWebSocketFrame) {
		ctx.channel().write(new PongWebSocketFrame(frame.content().retain()));
		return;
	}
	// 仅支持文本消息,不支持二进制消息
	if (!(frame instanceof TextWebSocketFrame)) {
		ctx.close();//(String.format("%s frame types not supported", frame.getClass().getName()));
		return;
	}

}
 
开发者ID:brenthub,项目名称:brent-pusher,代码行数:19,代码来源:NettyPusherServer.java

示例14: handle

import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; //导入依赖的package包/类
public void handle(ChannelHandlerContext ctx, WebSocketFrame frame) {
    if (frame instanceof CloseWebSocketFrame) {
        handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame);
        onClose(ctx);
        return;
    }
    if (frame instanceof PingWebSocketFrame) {
        ctx.channel().write(new PongWebSocketFrame(frame.content()));
        return;
    }
    if (!(frame instanceof TextWebSocketFrame)) {
        throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass()
                .getName()));
    }

    String msg = ((TextWebSocketFrame) frame).text();
    onMessage(ctx, msg);
}
 
开发者ID:buremba,项目名称:netty-rest,代码行数:19,代码来源:WebSocketService.java

示例15: handleWebSocketFrame

import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; //导入依赖的package包/类
public void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {

		// 判断是否是关闭链路的指令
		if (frame instanceof CloseWebSocketFrame) {
			handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
			return;
		}
		// 判断是否是Ping消息
		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()));
		}
		//返回应答消息
		String request= ((TextWebSocketFrame)frame).text();
		System.out.println(String.format("%s received %s", ctx.channel(), request));
		
		ctx.channel().write(new TextWebSocketFrame(request+" ,现在时刻:"+new Date()));
		
	}
 
开发者ID:zoopaper,项目名称:netty-study,代码行数:24,代码来源:WebSocketServerHandler.java


注:本文中的io.netty.handler.codec.http.websocketx.CloseWebSocketFrame类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。