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

Java WebSocketClientProtocolHandler类代码示例

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

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



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

示例1: fixHandlerBeforeConnect

import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandler; //导入依赖的package包/类
/**
	 * 适配
	 */
	@Override
	protected ChannelHandler fixHandlerBeforeConnect(final ChannelHandler handler) {
		ChannelHandler result=new ShareableChannelInboundHandler() {
			@Override
			public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
				Channel ch=ctx.channel();
				ch.pipeline().addLast(new HttpClientCodec());
            	ch.pipeline().addLast(new HttpObjectAggregator(64*1024));
            	ch.pipeline().addLast(new WebSocketClientProtocolHandler(WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders())));
            	ch.pipeline().addLast(new WebSocketConnectedClientHandler(handler));
				ctx.pipeline().remove(this);//移除当前handler
				ctx.pipeline().fireChannelRegistered();//重新从第一个handler抛出事件
			}
		};
//		ChannelInitializer<SocketChannel> result=new ChannelInitializer<SocketChannel>() {
//            @Override
//            protected void initChannel(SocketChannel ch) {
//            	ch.pipeline().addLast(new HttpClientCodec());
//            	ch.pipeline().addLast(new HttpObjectAggregator(64*1024));
//            	ch.pipeline().addLast(new WebSocketClientProtocolHandler(WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders())));
//            	ch.pipeline().addLast(new WebSocketConnectedClientHandler(handler));
//            }
//        };
        return result;
	}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:29,代码来源:NettyTextWebSocketClient.java


示例2: fixHandlerBeforeConnect

import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandler; //导入依赖的package包/类
/**
	 * 适配
	 */
	@Override
	protected ChannelHandler fixHandlerBeforeConnect(final ChannelHandler handler) {
		ChannelHandler result=new ShareableChannelInboundHandler() {
			@Override
			public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
				Channel ch=ctx.channel();
				ch.pipeline().addLast(new HttpClientCodec());
            	ch.pipeline().addLast(new HttpObjectAggregator(64*1024));
            	ch.pipeline().addLast(new WebSocketClientProtocolHandler(WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders())));
            	ch.pipeline().addLast(new WebSocketConnectedClientHandler(handler));
				ctx.pipeline().remove(this);//移除当前handler
				ctx.fireChannelRegistered();//重新从第一个handler抛出事件
			}
		};
//		ChannelInitializer<SocketChannel> result=new ChannelInitializer<SocketChannel>() {
//            @Override
//            protected void initChannel(SocketChannel ch) {
//            	ch.pipeline().addLast(new HttpClientCodec());
//            	ch.pipeline().addLast(new HttpObjectAggregator(64*1024));
//            	ch.pipeline().addLast(new WebSocketClientProtocolHandler(WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders())));
//            	ch.pipeline().addLast(new WebSocketConnectedClientHandler(handler));
//            }
//        };
        return result;
	}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:29,代码来源:NettyBinaryWebSocketClient.java


示例3: userEventTriggered

import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandler; //导入依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt == WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE) {
        // Handshake is completed
        String actualProtocol = handshaker.actualSubprotocol();
        serialization = WampSerialization.fromString(actualProtocol);
        if (serialization == WampSerialization.Invalid) {
            throw new WampError("Invalid Websocket Protocol");
        }
        
        // Install the serializer and deserializer
        ctx.pipeline()
           .addAfter(ctx.name(), "wamp-deserializer", 
                     new WampDeserializationHandler(serialization));
        ctx.pipeline()
           .addAfter(ctx.name(), "wamp-serializer", 
                     new WampSerializationHandler(serialization));
        
        // Fire the connection established event
        ctx.fireUserEventTriggered(new ConnectionEstablishedEvent(serialization));
        
    } else {
        ctx.fireUserEventTriggered(evt);
    }
}
 
开发者ID:Matthias247,项目名称:jawampa,代码行数:26,代码来源:WampClientWebsocketHandler.java


示例4: initChannel

import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandler; //导入依赖的package包/类
/**
 * 通道注册的时候配置websocket解码handler
 */
@Override
protected final void initChannel(Channel ch) throws Exception {
	ChannelPipeline pipeline=ch.pipeline();
	pipeline.addLast(new HttpClientCodec());
	pipeline.addLast(new ChunkedWriteHandler());
	pipeline.addLast(new HttpObjectAggregator(64*1024));
	pipeline.addLast(new WebSocketClientProtocolHandler(WebSocketClientHandshakerFactory.newHandshaker(new URI(url), WebSocketVersion.V13, null, false, new DefaultHttpHeaders())));
       pipeline.addLast(new WebSocketConnectedClientHandler());//连接成功监听handler
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:13,代码来源:WebSocketClientInitializer.java


示例5: userEventTriggered

import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandler; //导入依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt)
		throws Exception {
	if (evt == WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE)
	{
		log.debug("excute webSocketHandComplete……");
		webSocketHandComplete(ctx);
		ctx.pipeline().remove(this);
		log.debug("excuted webSocketHandComplete:"+ctx.pipeline().toMap().toString());
	}else
	{
		super.userEventTriggered(ctx, evt);
	}
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:15,代码来源:WebSocketClientInitializer.java


示例6: userEventTriggered

import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandler; //导入依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt)
		throws Exception {
	if (evt == WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE) {
		log.log(logLevel,"WebSocket:HANDSHAKE_COMPLETE,pipeline:"+ctx.channel().pipeline().toMap().toString());
		ctx.pipeline().addLast(new WebSocketTextFrameByteBufAdapter());//适配器
		ctx.pipeline().addLast(this.handler);//业务层handler
		//为新加的handler手动触发必要事件
		ctx.fireChannelRegistered();
		ctx.fireChannelActive();
		log.log(logLevel,"HANDSHAKE_COMPLETED HANDLERS:"+ctx.channel().pipeline().toMap().toString());
	}
	super.userEventTriggered(ctx, evt);
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:15,代码来源:NettyTextWebSocketClient.java


示例7: userEventTriggered

import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandler; //导入依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt)
		throws Exception {
	if (evt == WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE) {
		log.log(logLevel,"WebSocket:HANDSHAKE_COMPLETE,pipeline:"+ctx.channel().pipeline().toMap().toString());
		ctx.pipeline().addLast(new WebSocketBinaryFrameByteBufAdapter());//适配器
		ctx.pipeline().addLast(this.handler);//业务层handler
		//为新加的handler手动触发必要事件
		ctx.fireChannelRegistered();
		ctx.fireChannelActive();
		log.log(logLevel,"HANDSHAKE_COMPLETED HANDLERS:"+ctx.channel().pipeline().toMap().toString());
	}
	super.userEventTriggered(ctx, evt);
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:15,代码来源:NettyBinaryWebSocketClient.java


示例8: initChannel

import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandler; //导入依赖的package包/类
@Override
protected void initChannel(final NioSocketChannel ch)
        throws Exception {
    URI uri = new URI("ws", null, host, port, "/game/" + (username == null ? "" : uriEncode(username)), null, null);
    System.out.println(uri);

    notificationChannel = ch;
    ch.pipeline().addLast(
            new HttpClientCodec(),
            new HttpObjectAggregator(65536),
            new WebSocketClientProtocolHandler(uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders(), 65536, true),
            new MessageCodec(),
            new NotificationHandler());
}
 
开发者ID:h4ssi,项目名称:mmo-client,代码行数:15,代码来源:ServerConnection.java


示例9: userEventTriggered

import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandler; //导入依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
	super.userEventTriggered(ctx, evt);
	
	Logger.debug("ue: " + evt);
	
	if (evt == WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE) {
		Logger.debug("handshake done");
        //this.handshaker = null;
        this.wsready.release();
	}
}
 
开发者ID:Gadreel,项目名称:divconq,代码行数:13,代码来源:ClientHandler.java


示例10: addToPipeline

import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandler; //导入依赖的package包/类
@Override
public void addToPipeline(final ChannelPipeline pipeline) {
    pipeline.addLast("http-codec", new HttpClientCodec());
    pipeline.addLast("aggregator", new HttpObjectAggregator(8192));

    final WebSocketClientHandshaker handShaker = new WhiteSpaceInPathWebSocketClientHandshaker13(serverUri,
            WebSocketVersion.V13, PROTOCOL, false, createHttpHeaders(httpHeaders), Integer.MAX_VALUE);
    pipeline.addLast("websocket-protocol-handler", new WebSocketClientProtocolHandler(handShaker));

    pipeline.addLast("websocket-frame-codec", new ByteBufToWebSocketFrameCodec());
}
 
开发者ID:saxsys,项目名称:SynchronizeFX,代码行数:12,代码来源:WebsocketChannelInitializer.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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