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


Java WebSocketVersion类代码示例

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


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

示例1: connect

import org.jboss.netty.handler.codec.http.websocketx.WebSocketVersion; //导入依赖的package包/类
public static ClientChannel connect(LoggerFactory loggerFactory, URI uri,
        int connectTimeoutMillis) throws ChannelException {
    Logger logger = loggerFactory.create(String.format("WebSocketClientHandler-%s", uri));

    WebSocketClientChannel clientChannel = new WebSocketClientChannel();
    clientChannel.setUri(uri);

    ConnectingChannelHandler handler = new ConnectingChannelHandler();
    clientChannel.setChannelHandler(handler);

    WebSocketClientUpstreamHandler wsHandler = new WebSocketClientUpstreamHandler(logger,
            clientChannel);
    ChannelPipeline pipeline = Channels.pipeline();
    pipeline.addLast("decoder", new HttpResponseDecoder());
    pipeline.addLast("encoder", new HttpRequestEncoder());
    // connect
    Channel channel = prepareAndConnect(logger, uri, pipeline, wsHandler,
            uri.getScheme().equalsIgnoreCase("wss"), connectTimeoutMillis);
    // handshake
    try {
        WebSocketClientHandshaker handshaker = wsFactory.newHandshaker(uri,
                WebSocketVersion.V13, null, true, WebSocketClientHelper.getHeaders(uri));
        wsHandler.handshaker = handshaker;
        handshaker.handshake(channel);
        // return maybe fast than call
        if (!wsHandler.handshaker.isHandshakeComplete() && (handler.error == null)) {
            synchronized (handler.syncObject) {
                handler.syncObject.wait(connectTimeoutMillis);
            }
        }
    } catch (Exception e) {
        throw new ChannelException(Text.WS_HANDSHAKE_ERROR, e);
    }

    if (wsHandler.handshaker.isHandshakeComplete()) {
        return clientChannel;
    }
    if (handler.error != null) {
        throw new ChannelException(Text.CONNECT_FAIL + ": " + handler.error.getMessage(),
                handler.error);
    }

    throw new ChannelException(Text.CONNECT_TIMEOUT);
}
 
开发者ID:kuiwang,项目名称:my-dev,代码行数:45,代码来源:WebSocketClient.java

示例2: NettyWSClient

import org.jboss.netty.handler.codec.http.websocketx.WebSocketVersion; //导入依赖的package包/类
public NettyWSClient(String uriStr, WebSocketClient webSocketClient)
{
	
	this.t = webSocketClient;
	this.uri = URI.create(uriStr);
	

	String protocol = this.uri.getScheme();
	if (!protocol.equals("ws"))
	{
		throw new IllegalArgumentException("Unsupported protocol: " + protocol);
	}
	
	ClientBootstrap bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
	
	Channel ch = null;

	HashMap<String, String> customHeaders = new HashMap<String, String>();
	customHeaders.put("MyHeader", "MyValue");
	
	// 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.
	this.handshaker = new WebSocketClientHandshakerFactory().newHandshaker(this.uri, WebSocketVersion.V13, null, false, customHeaders);
	
	bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
		public ChannelPipeline getPipeline() throws Exception
		{
			ChannelPipeline pipeline = Channels.pipeline();
			
			pipeline.addLast("decoder", new HttpResponseDecoder());
			pipeline.addLast("encoder", new HttpRequestEncoder());
			pipeline.addLast("ws-handler", NettyWSClient.this);
			return pipeline;
		}
	});
	
	ChannelFuture future = bootstrap.connect(new InetSocketAddress(this.uri.getHost(), this.uri.getPort()));
	future.syncUninterruptibly();
	ch = future.getChannel();
	try
	{
		this.handshaker.handshake(ch);
	}
	catch (Exception e)
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:EricssonResearch,项目名称:trap,代码行数:51,代码来源:NettyWSClient.java


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