本文整理汇总了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);
}
示例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();
}
}