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


Java WebSocketClientProtocolHandler类代码示例

本文整理汇总了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;未经允许,请勿转载。