• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java WebSocketClientCompressionHandler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: onOpen

import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketClientCompressionHandler; //导入依赖的package包/类
@Override
public void onOpen(Session session, EndpointConfig config) {
    String id = session.getId();
    log.debug("{}: open ws proxy ", id);
    try {
        ChannelFuture cf = backend.connect().sync();
        Channel channel = cf.channel();
        WebSocketClientProtocolHandler wscph = makeWsProtocolHandler(session);
        WebSocketClientHandshaker handshaker = wscph.handshaker();
        WsHandler handler = new WsHandler(handshaker, channel, session);
        channel.pipeline().addLast(new HttpObjectAggregator(1024 * 4),
          WebSocketClientCompressionHandler.INSTANCE,
          wscph,
          handler);
        handshaker.handshake(channel);
        log.debug("{}: wait messages", id);
        session.addMessageHandler(String.class, handler::onFrontString);
        session.addMessageHandler(ByteBuffer.class, handler::onFrontBytes);
    } catch (Exception e) {
        log.error("{}: can not establish ws connect with backed", id, e);
    }

}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:24,代码来源:WsProxy.java


示例2: initChannel

import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketClientCompressionHandler; //导入依赖的package包/类
@Override
protected void initChannel(final Channel channel) throws Exception
{
    final ChannelPipeline pipeline = channel.pipeline();
    pipeline.addLast("Bridge|SSLContext", this.webSocketConnection.getSslContext().newHandler(channel.alloc(), this.webSocketConnection.getIp(), this.webSocketConnection.getPort()));
    pipeline.addLast("Bridge|HttpClientCodec", new HttpClientCodec());
    pipeline.addLast("Bridge|HttpObjectAggregator", new HttpObjectAggregator(8192));
    pipeline.addLast("Bridge|WebSocketClientCompressionHandler", WebSocketClientCompressionHandler.INSTANCE);
    pipeline.addLast(new WebSocketHandler(this.webSocketConnection));
}
 
开发者ID:MrGregorix,项目名称:SlackDiscordBridge,代码行数:11,代码来源:WebSocketChannelInitializer.java


示例3: handhshake

import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketClientCompressionHandler; //导入依赖的package包/类
/**
 * @return true if the handshake is done properly.
 * @throws URISyntaxException   throws if there is an error in the URI syntax.
 * @throws InterruptedException throws if the connecting the server is interrupted.
 */
public boolean handhshake() throws InterruptedException, URISyntaxException, SSLException, ProtocolException {
    boolean isSuccess;
    URI uri = new URI(url);
    String scheme = uri.getScheme() == null ? "ws" : uri.getScheme();
    final String host = uri.getHost() == null ? "127.0.0.1" : uri.getHost();
    final int port;
    if (uri.getPort() == -1) {
        if ("ws".equalsIgnoreCase(scheme)) {
            port = 80;
        } else if ("wss".equalsIgnoreCase(scheme)) {
            port = 443;
        } else {
            port = -1;
        }
    } else {
        port = uri.getPort();
    }

    if (!"ws".equalsIgnoreCase(scheme) && !"wss".equalsIgnoreCase(scheme)) {
        logger.error("Only WS(S) is supported.");
        return false;
    }

    final boolean ssl = "wss".equalsIgnoreCase(scheme);
    final SslContext sslCtx;
    if (ssl) {
        sslCtx = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
    } else {
        sslCtx = null;
    }

    group = new NioEventLoopGroup();

    HttpHeaders headers = new DefaultHttpHeaders();
    for (Map.Entry<String, String> entry : customHeaders.entrySet()) {
        headers.add(entry.getKey(), entry.getValue());
    }
    // Connect with V13 (RFC 6455 aka HyBi-17). You can change it to V08 or V00.
    // If you change it to V00, ping is not supported and remember to change
    // HttpResponseDecoder to WebSocketHttpResponseDecoder in the pipeline.
    handler = new WebSocketClientHandler(
            WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, subProtocol, true, headers),
            latch);

    Bootstrap bootstrap = new Bootstrap();
    bootstrap.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {
        @Override
        protected void initChannel(SocketChannel ch) {
            ChannelPipeline p = ch.pipeline();
            if (sslCtx != null) {
                p.addLast(sslCtx.newHandler(ch.alloc(), host, port));
            }
            p.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192),
                    WebSocketClientCompressionHandler.INSTANCE, handler);
        }
    });

    channel = bootstrap.connect(uri.getHost(), port).sync().channel();
    isSuccess = handler.handshakeFuture().sync().isSuccess();
    logger.info("WebSocket Handshake successful : " + isSuccess);
    return isSuccess;
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:68,代码来源:WebSocketTestClient.java


示例4: connect

import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketClientCompressionHandler; //导入依赖的package包/类
@Override
public void connect() throws InterruptedException{
	// Connect with V13 (RFC 6455 aka HyBi-17). You can change it to V08 or V00.
	// If you change it to V00, ping is not supported and remember to change
	// HttpResponseDecoder to WebSocketHttpResponseDecoder in the pipeline.
	handler =
			new WebSocketClientHandler(
					WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, true, new DefaultHttpHeaders(),this.getMaxPayload()));


	//make sure the handler has a refernce to this object.
	handler.setClient(this);

	Bootstrap clientBoot = new Bootstrap();
	clientBoot.group(group)
	.channel(NioSocketChannel.class)
	.handler(new ChannelInitializer<SocketChannel>() {

		@Override
		protected void initChannel(SocketChannel ch) {
			ChannelPipeline p = ch.pipeline();
			SSLEngine sslEngine=null;
			if(AbstractClient.this.isEncrypted()){
				if(sslContext == null){
					sslEngine = new SSLFactory().createClientSslCtx(Config.getInstance()).newEngine(ch.alloc(), uri.getHost(),uri.getPort());
				}else{
					sslEngine = sslContext.newEngine(ch.alloc(),uri.getHost(),uri.getPort());
				}
				
				sslEngine.setEnabledProtocols(Const.TLS_PROTOCOLS);
				sslEngine.setUseClientMode(true);
				p.addLast(new SslHandler(sslEngine));
			}

			p.addLast( new HttpClientCodec());
			p.addLast(new HttpObjectAggregator(8192));
			if(AbstractClient.this.isCompress()){
				p.addLast(WebSocketClientCompressionHandler.INSTANCE);
			}
			p.addLast(handler);


		}
	});


	this.ch = clientBoot.connect(uri.getHost(), uri.getPort()).sync().channel();
	handler.handshakeFuture().sync();	

}
 
开发者ID:mwambler,项目名称:xockets.io,代码行数:51,代码来源:AbstractClient.java


示例5: handhshake

import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketClientCompressionHandler; //导入依赖的package包/类
/**
 * @return true if the handshake is done properly.
 * @throws URISyntaxException throws if there is an error in the URI syntax.
 * @throws InterruptedException throws if the connecting the server is interrupted.
 */
public boolean handhshake() throws InterruptedException, URISyntaxException, SSLException {
    boolean isDone;
    URI uri = new URI(url);
    String scheme = uri.getScheme() == null ? "ws" : uri.getScheme();
    final String host = uri.getHost() == null ? "127.0.0.1" : uri.getHost();
    final int port;
    if (uri.getPort() == -1) {
        if ("ws".equalsIgnoreCase(scheme)) {
            port = 80;
        } else if ("wss".equalsIgnoreCase(scheme)) {
            port = 443;
        } else {
            port = -1;
        }
    } else {
        port = uri.getPort();
    }

    if (!"ws".equalsIgnoreCase(scheme) && !"wss".equalsIgnoreCase(scheme)) {
        logger.error("Only WS(S) is supported.");
        return false;
    }

    final boolean ssl = "wss".equalsIgnoreCase(scheme);
    final SslContext sslCtx;
    if (ssl) {
        sslCtx = SslContextBuilder.forClient()
                                  .trustManager(InsecureTrustManagerFactory.INSTANCE).build();
    } else {
        sslCtx = null;
    }

    group = new NioEventLoopGroup();

    HttpHeaders headers = new DefaultHttpHeaders();
    customHeaders.entrySet().forEach(
            header -> headers.add(header.getKey(), header.getValue())
    );
    try {
        // Connect with V13 (RFC 6455 aka HyBi-17). You can change it to V08 or V00.
        // If you change it to V00, ping is not supported and remember to change
        // HttpResponseDecoder to WebSocketHttpResponseDecoder in the pipeline.
        handler =
                new WebSocketClientHandler(
                        WebSocketClientHandshakerFactory.newHandshaker(
                                uri, WebSocketVersion.V13, subProtocol,
                                true, headers));

        Bootstrap b = new Bootstrap();
        b.group(group)
         .channel(NioSocketChannel.class)
         .handler(new ChannelInitializer<SocketChannel>() {
             @Override
             protected void initChannel(SocketChannel ch) {
                 ChannelPipeline p = ch.pipeline();
                 if (sslCtx != null) {
                     p.addLast(sslCtx.newHandler(ch.alloc(), host, port));
                 }
                 p.addLast(
                         new HttpClientCodec(),
                         new HttpObjectAggregator(8192),
                         WebSocketClientCompressionHandler.INSTANCE,
                         handler);
             }
         });

        channel = b.connect(uri.getHost(), port).sync().channel();
        isDone = handler.handshakeFuture().sync().isSuccess();
        logger.debug("WebSocket Handshake successful : " + isDone);
        return isDone;
    } catch (Exception e) {
        logger.error("Handshake unsuccessful : " + e.getMessage(), e);
        return false;
    }
}
 
开发者ID:wso2,项目名称:msf4j,代码行数:81,代码来源:WebSocketClient.java


示例6: handhshake

import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketClientCompressionHandler; //导入依赖的package包/类
/**
 * @return true if the handshake is done properly.
 * @throws URISyntaxException throws if there is an error in the URI syntax.
 * @throws InterruptedException throws if the connecting the server is interrupted.
 */
public boolean handhshake() throws InterruptedException, URISyntaxException, SSLException, ProtocolException {
    boolean isSuccess;
    URI uri = new URI(url);
    String scheme = uri.getScheme() == null ? "ws" : uri.getScheme();
    final String host = uri.getHost() == null ? "127.0.0.1" : uri.getHost();
    final int port;
    if (uri.getPort() == -1) {
        if ("ws".equalsIgnoreCase(scheme)) {
            port = 80;
        } else if ("wss".equalsIgnoreCase(scheme)) {
            port = 443;
        } else {
            port = -1;
        }
    } else {
        port = uri.getPort();
    }

    if (!"ws".equalsIgnoreCase(scheme) && !"wss".equalsIgnoreCase(scheme)) {
        logger.error("Only WS(S) is supported.");
        return false;
    }

    final boolean ssl = "wss".equalsIgnoreCase(scheme);
    final SslContext sslCtx;
    if (ssl) {
        sslCtx = SslContextBuilder.forClient()
                .trustManager(InsecureTrustManagerFactory.INSTANCE).build();
    } else {
        sslCtx = null;
    }

    group = new NioEventLoopGroup();

    HttpHeaders headers = new DefaultHttpHeaders();
    customHeaders.entrySet().forEach(
            header -> headers.add(header.getKey(), header.getValue())
    );
    try {
        // Connect with V13 (RFC 6455 aka HyBi-17). You can change it to V08 or V00.
        // If you change it to V00, ping is not supported and remember to change
        // HttpResponseDecoder to WebSocketHttpResponseDecoder in the pipeline.
        handler =
                new WebSocketClientHandler(
                        WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, subProtocol,
                                                                       true, headers), latch);

        Bootstrap b = new Bootstrap();
        b.group(group)
                .channel(NioSocketChannel.class)
                .handler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    protected void initChannel(SocketChannel ch) {
                        ChannelPipeline p = ch.pipeline();
                        if (sslCtx != null) {
                            p.addLast(sslCtx.newHandler(ch.alloc(), host, port));
                        }
                        p.addLast(
                                new HttpClientCodec(),
                                new HttpObjectAggregator(8192),
                                WebSocketClientCompressionHandler.INSTANCE,
                                handler);
                    }
                });

        channel = b.connect(uri.getHost(), port).sync().channel();
        isSuccess = handler.handshakeFuture().sync().isSuccess();
        logger.debug("WebSocket Handshake successful : " + isSuccess);
        return isSuccess;
    } catch (Exception e) {
        logger.error("Handshake unsuccessful : " + e.getMessage());
        throw new ProtocolException("Protocol exception: " + e.getMessage());
    }
}
 
开发者ID:wso2,项目名称:carbon-transports,代码行数:80,代码来源:WebSocketTestClient.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CombineSequenceFileInputFormat类代码示例发布时间:2022-05-22
下一篇:
Java PowerModel类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap