io.netty.handler.codec.http.websocketx.WebSocket13FrameEncoder Java Examples
The following examples show how to use
io.netty.handler.codec.http.websocketx.WebSocket13FrameEncoder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpUpgradeHandler.java From cute-proxy with BSD 2-Clause "Simplified" License | 6 votes |
private void upgradeWebSocket(ChannelHandlerContext ctx) { logger.debug("upgrade to web-socket"); ctx.pipeline().replace("http-interceptor", "ws-interceptor", new WebSocketInterceptor(address.host(), wsUrl, messageListener)); ctx.pipeline().remove(HttpClientCodec.class); WebSocketFrameDecoder frameDecoder = new WebSocket13FrameDecoder(false, true, 65536, false); WebSocketFrameEncoder frameEncoder = new WebSocket13FrameEncoder(true); ctx.pipeline().addBefore("ws-interceptor", "ws-decoder", frameDecoder); ctx.pipeline().addBefore("ws-interceptor", "ws-encoder", frameEncoder); localPipeline.remove(HttpServerCodec.class); WebSocketFrameDecoder clientFrameDecoder = new WebSocket13FrameDecoder(true, true, 65536, false); WebSocketFrameEncoder clientFrameEncoder = new WebSocket13FrameEncoder(false); localPipeline.addBefore("replay-handler", "ws-decoder", clientFrameDecoder); localPipeline.addBefore("replay-handler", "ws-encoder", clientFrameEncoder); }
Example #2
Source File: WsServerChannelInitializer.java From fastjgame with Apache License 2.0 | 5 votes |
private void appendWebsocketCodec(ChannelPipeline pipeline) { // websocket 解码流程 // websocket协议处理器(握手、心跳等) pipeline.addLast(new WebSocketServerProtocolHandler(websocketPath)); pipeline.addLast(new BinaryWebSocketFrameToBytesDecoder()); // websocket 编码流程 // Web socket clients must set this to true to mask payload. // Server implementations must set this to false. pipeline.addLast(new WebSocket13FrameEncoder(false)); // 将ByteBuf转换为websocket二进制帧 pipeline.addLast(new BytesToBinaryWebSocketFrameEncoder()); }
Example #3
Source File: WsClientChannelInitializer.java From fastjgame with Apache License 2.0 | 5 votes |
/** * websocket协议支持 */ private void appendWebsocketCodec(ChannelPipeline pipeline) throws URISyntaxException { // websocket 解码流程 URI uri = new URI(websocketUrl); pipeline.addLast(new WebSocketClientProtocolHandler(uri, WebSocketVersion.V13, null, true, new DefaultHttpHeaders(), sessionConfig.maxFrameLength())); pipeline.addLast(new BinaryWebSocketFrameToBytesDecoder()); // websocket 编码流程 // Web socket clients must set this to true to mask payload. // Server implementations must set this to false. pipeline.addLast(new WebSocket13FrameEncoder(true)); // 将ByteBuf转换为websocket二进制帧 pipeline.addLast(new BytesToBinaryWebSocketFrameEncoder()); }
Example #4
Source File: Handshake.java From quarkus-http with Apache License 2.0 | 4 votes |
/** * Issue the WebSocket upgrade * * @param exchange The {@link WebSocketHttpExchange} for which the handshake and upgrade should occur. */ public final void handshake(final WebSocketHttpExchange exchange, Consumer<ChannelHandlerContext> completeListener) { String origin = exchange.getRequestHeader(HttpHeaderNames.ORIGIN); if (origin != null) { exchange.setResponseHeader(HttpHeaderNames.ORIGIN, origin); } selectSubprotocol(exchange); List<WebSocketServerExtension> extensions = selectExtensions(exchange); exchange.setResponseHeader(HttpHeaderNames.SEC_WEB_SOCKET_LOCATION, getWebSocketLocation(exchange)); final String key = exchange.getRequestHeader(HttpHeaderNames.SEC_WEB_SOCKET_KEY); try { final String solution = solve(key); exchange.setResponseHeader(HttpHeaderNames.SEC_WEB_SOCKET_ACCEPT, solution); performUpgrade(exchange); } catch (NoSuchAlgorithmException e) { exchange.endExchange(); return; } handshakeInternal(exchange); exchange.upgradeChannel(new Consumer<Object>() { @Override public void accept(Object c) { ChannelHandlerContext context = (ChannelHandlerContext) c; WebSocket13FrameDecoder decoder = new WebSocket13FrameDecoder(true, allowExtensions, maxFrameSize, false); WebSocket13FrameEncoder encoder = new WebSocket13FrameEncoder(false); ChannelPipeline p = context.pipeline(); if (p.get(HttpObjectAggregator.class) != null) { p.remove(HttpObjectAggregator.class); } if (p.get(HttpContentCompressor.class) != null) { p.remove(HttpContentCompressor.class); } p.addLast("ws-encoder", encoder); p.addLast("ws-decoder", decoder); for(WebSocketServerExtension extension : extensions) { WebSocketExtensionDecoder exdecoder = extension.newExtensionDecoder(); WebSocketExtensionEncoder exencoder = extension.newExtensionEncoder(); p.addAfter("ws-decoder", exdecoder.getClass().getName(), exdecoder); p.addAfter("ws-encoder", exencoder.getClass().getName(), exencoder); } completeListener.accept(context); } }); }