當前位置: 首頁>>代碼示例>>Java>>正文


Java WebSocketVersion類代碼示例

本文整理匯總了Java中io.netty.handler.codec.http.websocketx.WebSocketVersion的典型用法代碼示例。如果您正苦於以下問題:Java WebSocketVersion類的具體用法?Java WebSocketVersion怎麽用?Java WebSocketVersion使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


WebSocketVersion類屬於io.netty.handler.codec.http.websocketx包,在下文中一共展示了WebSocketVersion類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: fixHandlerBeforeConnect

import io.netty.handler.codec.http.websocketx.WebSocketVersion; //導入依賴的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.WebSocketVersion; //導入依賴的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: configure

import io.netty.handler.codec.http.websocketx.WebSocketVersion; //導入依賴的package包/類
@Override
public void configure(final ChannelPipeline pipeline) {
    final String scheme = connection.getUri().getScheme();
    if (!"ws".equalsIgnoreCase(scheme) && !"wss".equalsIgnoreCase(scheme))
        throw new IllegalStateException("Unsupported scheme (only ws: or wss: supported): " + scheme);

    if (!supportsSsl() && "wss".equalsIgnoreCase(scheme))
        throw new IllegalStateException("To use wss scheme ensure that enableSsl is set to true in configuration");

    final int maxContentLength = cluster.connectionPoolSettings().maxContentLength;
    handler = new WebSocketClientHandler(
            WebSocketClientHandshakerFactory.newHandshaker(
                    connection.getUri(), WebSocketVersion.V13, null, false, HttpHeaders.EMPTY_HEADERS, maxContentLength));

    pipeline.addLast("http-codec", new HttpClientCodec());
    pipeline.addLast("aggregator", new HttpObjectAggregator(maxContentLength));
    pipeline.addLast("ws-handler", handler);
    pipeline.addLast("gremlin-encoder", webSocketGremlinRequestEncoder);
    pipeline.addLast("gremlin-decoder", webSocketGremlinResponseDecoder);
}
 
開發者ID:PKUSilvester,項目名稱:LiteGraph,代碼行數:21,代碼來源:Channelizer.java

示例4: WebSocketClient

import io.netty.handler.codec.http.websocketx.WebSocketVersion; //導入依賴的package包/類
public WebSocketClient(String host, int port, String path, boolean isSSL) throws Exception {
    super(host, port, new Random());

    String scheme = isSSL ? "wss://" : "ws://";
    URI uri = new URI(scheme + host + ":" + port + path);

    if (isSSL) {
        sslCtx = SslContextBuilder.forClient().sslProvider(SslProvider.JDK).trustManager(InsecureTrustManagerFactory.INSTANCE).build();
    } else {
        sslCtx = null;
    }

    this.handler = new WebSocketClientHandler(
                    WebSocketClientHandshakerFactory.newHandshaker(
                            uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders()));
}
 
開發者ID:blynkkk,項目名稱:blynk-server,代碼行數:17,代碼來源:WebSocketClient.java

示例5: WebSocketClientHandler

import io.netty.handler.codec.http.websocketx.WebSocketVersion; //導入依賴的package包/類
WebSocketClientHandler(
    URI uri, String userAgent, WebsocketConnection.WSClientEventHandler delegate) {
  this.delegate = checkNotNull(delegate, "delegate must not be null");
  checkArgument(!Strings.isNullOrEmpty(userAgent), "user agent must not be null or empty");
  this.handshaker = WebSocketClientHandshakerFactory.newHandshaker(
      uri, WebSocketVersion.V13, null, true,
      new DefaultHttpHeaders().add("User-Agent", userAgent));
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:9,代碼來源:NettyWebSocketClient.java

示例6: initChannel

import io.netty.handler.codec.http.websocketx.WebSocketVersion; //導入依賴的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

示例7: setup

import io.netty.handler.codec.http.websocketx.WebSocketVersion; //導入依賴的package包/類
@Before
public void setup() throws Exception {
    s = new Server(conf);
    s.run();

    Connector con = mac.getConnector("root", "secret");
    con.securityOperations().changeUserAuthorizations("root", new Authorizations("A", "B", "C", "D", "E", "F"));

    this.sessionId = UUID.randomUUID().toString();
    AuthCache.getCache().put(sessionId, token);
    group = new NioEventLoopGroup();
    SslContext ssl = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();

    String cookieVal = ClientCookieEncoder.STRICT.encode(Constants.COOKIE_NAME, sessionId);
    HttpHeaders headers = new DefaultHttpHeaders();
    headers.add(Names.COOKIE, cookieVal);

    WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(LOCATION,
            WebSocketVersion.V13, (String) null, false, headers);
    handler = new ClientHandler(handshaker);
    Bootstrap boot = new Bootstrap();
    boot.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline().addLast("ssl", ssl.newHandler(ch.alloc(), "127.0.0.1", WS_PORT));
            ch.pipeline().addLast(new HttpClientCodec());
            ch.pipeline().addLast(new HttpObjectAggregator(8192));
            ch.pipeline().addLast(handler);
        }
    });
    ch = boot.connect("127.0.0.1", WS_PORT).sync().channel();
    // Wait until handshake is complete
    while (!handshaker.isHandshakeComplete()) {
        sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
        LOG.debug("Waiting for Handshake to complete");
    }
}
 
開發者ID:NationalSecurityAgency,項目名稱:qonduit,代碼行數:39,代碼來源:WebSocketIT.java

示例8: WebSocketClient

import io.netty.handler.codec.http.websocketx.WebSocketVersion; //導入依賴的package包/類
public WebSocketClient(final URI uri) {
    super("ws-client-%d");
    final Bootstrap b = new Bootstrap().group(group);
    b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);

    final String protocol = uri.getScheme();
    if (!"ws".equals(protocol))
        throw new IllegalArgumentException("Unsupported protocol: " + protocol);

    try {
        final WebSocketClientHandler wsHandler =
                new WebSocketClientHandler(
                        WebSocketClientHandshakerFactory.newHandshaker(
                                uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders()));
        final MessageSerializer serializer = new GryoMessageSerializerV1d0();
        b.channel(NioSocketChannel.class)
                .handler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    protected void initChannel(final SocketChannel ch) {
                        final ChannelPipeline p = ch.pipeline();
                        p.addLast(
                                new HttpClientCodec(),
                                new HttpObjectAggregator(8192),
                                wsHandler,
                                new WebSocketGremlinRequestEncoder(true, serializer),
                                new WebSocketGremlinResponseDecoder(serializer),
                                callbackResponseHandler);
                    }
                });

        channel = b.connect(uri.getHost(), uri.getPort()).sync().channel();
        wsHandler.handshakeFuture().sync();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
開發者ID:PKUSilvester,項目名稱:LiteGraph,代碼行數:37,代碼來源:WebSocketClient.java

示例9: getWsVersion

import io.netty.handler.codec.http.websocketx.WebSocketVersion; //導入依賴的package包/類
static WebSocketVersion getWsVersion(String str) {
    switch (str) {
        case "0":
            return WebSocketVersion.V00;
        case "7":
            return WebSocketVersion.V07;
        case "8":
            return WebSocketVersion.V08;
        case "13":
            return WebSocketVersion.V13;
    }
    return WebSocketVersion.UNKNOWN;
}
 
開發者ID:codeabovelab,項目名稱:haven-platform,代碼行數:14,代碼來源:Utils.java

示例10: handleWebSocketResponse

import io.netty.handler.codec.http.websocketx.WebSocketVersion; //導入依賴的package包/類
private void handleWebSocketResponse(ChannelHandlerContext ctx, Outgoing out) {
    WebSocketHttpResponse response = (WebSocketHttpResponse) out.message;
    WebSocketServerHandshaker handshaker = response.handshakerFactory().newHandshaker(lastRequest);

    if (handshaker == null) {
        HttpResponse res = new DefaultFullHttpResponse(
                HttpVersion.HTTP_1_1,
                HttpResponseStatus.UPGRADE_REQUIRED);
        res.headers().set(HttpHeaderNames.SEC_WEBSOCKET_VERSION, WebSocketVersion.V13.toHttpHeaderValue());
        HttpUtil.setContentLength(res, 0);
        super.unbufferedWrite(ctx, new Outgoing(res, out.promise));
        response.subscribe(new CancelledSubscriber<>());
    } else {
        // First, insert new handlers in the chain after us for handling the websocket
        ChannelPipeline pipeline = ctx.pipeline();
        HandlerPublisher<WebSocketFrame> publisher = new HandlerPublisher<>(ctx.executor(), WebSocketFrame.class);
        HandlerSubscriber<WebSocketFrame> subscriber = new HandlerSubscriber<>(ctx.executor());
        pipeline.addAfter(ctx.executor(), ctx.name(), "websocket-subscriber", subscriber);
        pipeline.addAfter(ctx.executor(), ctx.name(), "websocket-publisher", publisher);

        // Now remove ourselves from the chain
        ctx.pipeline().remove(ctx.name());

        // Now do the handshake
        // Wrap the request in an empty request because we don't need the WebSocket handshaker ignoring the body,
        // we already have handled the body.
        handshaker.handshake(ctx.channel(), new EmptyHttpRequest(lastRequest));

        // And hook up the subscriber/publishers
        response.subscribe(subscriber);
        publisher.subscribe(response);
    }

}
 
開發者ID:playframework,項目名稱:netty-reactive-streams,代碼行數:35,代碼來源:HttpStreamsServerHandler.java

示例11: openConnection

import io.netty.handler.codec.http.websocketx.WebSocketVersion; //導入依賴的package包/類
public void openConnection() throws InterruptedException{
    Bootstrap bootstrap = new Bootstrap();

    final WebSocketClientHandler handler =
            new WebSocketClientHandler(
                    WebSocketClientHandshakerFactory.newHandshaker(
                            mUri, WebSocketVersion.V08, null, false,
                            new DefaultHttpHeaders()));

    bootstrap.group(mGroup)
    .channel(NioSocketChannel.class)
    .handler(new ChannelInitializer<SocketChannel>() {
                @Override
                public void initChannel(SocketChannel socketChannel){
                    ChannelPipeline channelPipeline =
                            socketChannel.pipeline();
                    channelPipeline.addLast(mSslContext.newHandler(
                            socketChannel.alloc(),
                            mUri.getHost(),
                            PORT));
                    channelPipeline.addLast(new HttpClientCodec(),
                            new HttpObjectAggregator(8192),
                            handler);
                }
            });

    mChannel = bootstrap.connect(mUri.getHost(), PORT).sync().channel();
    handler.handshakeFuture().sync();
    setConnected(Boolean.TRUE);
}
 
開發者ID:bitsoex,項目名稱:bitso-java,代碼行數:31,代碼來源:BitsoWebSocket.java

示例12: initChannel

import io.netty.handler.codec.http.websocketx.WebSocketVersion; //導入依賴的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

示例13: init

import io.netty.handler.codec.http.websocketx.WebSocketVersion; //導入依賴的package包/類
/**
 * Inits the.
 *
 * @throws URISyntaxException
 *           the URI syntax exception
 */
public void init() throws URISyntaxException {
  handshaker = WebSocketClientHandshakerFactory.newHandshaker(createUri(),
      WebSocketVersion.V13,
      null,
      false,
      customHeaders);
}
 
開發者ID:mrstampy,項目名稱:gameboot,代碼行數:14,代碼來源:WebSocketHandler.java

示例14: WebSocketClient

import io.netty.handler.codec.http.websocketx.WebSocketVersion; //導入依賴的package包/類
public WebSocketClient(final URI uri) {
    super("ws-client-%d");
    final Bootstrap b = new Bootstrap().group(group);
    b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);

    final String protocol = uri.getScheme();
    if (!"ws".equals(protocol))
        throw new IllegalArgumentException("Unsupported protocol: " + protocol);

    try {
        final WebSocketClientHandler wsHandler =
                new WebSocketClientHandler(
                        WebSocketClientHandshakerFactory.newHandshaker(
                                uri, WebSocketVersion.V13, null, false, HttpHeaders.EMPTY_HEADERS, 65536));
        final MessageSerializer serializer = new GryoMessageSerializerV3d0();
        b.channel(NioSocketChannel.class)
                .handler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    protected void initChannel(final SocketChannel ch) {
                        final ChannelPipeline p = ch.pipeline();
                        p.addLast(
                                new HttpClientCodec(),
                                new HttpObjectAggregator(65536),
                                wsHandler,
                                new WebSocketGremlinRequestEncoder(true, serializer),
                                new WebSocketGremlinResponseDecoder(serializer),
                                callbackResponseHandler);
                    }
                });

        channel = b.connect(uri.getHost(), uri.getPort()).sync().channel();
        wsHandler.handshakeFuture().get(10000, TimeUnit.MILLISECONDS);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
開發者ID:apache,項目名稱:tinkerpop,代碼行數:37,代碼來源:WebSocketClient.java

示例15: WebsocketClientHandler

import io.netty.handler.codec.http.websocketx.WebSocketVersion; //導入依賴的package包/類
/**
 * Creates a new WebSocketClientHandler that manages the BlaubotWebsocketConnection
 * @param uri                  The uri to connect with
 * @param remoteUniqueDeviceId the unique device id of the device we are connecting to
 * @param listenerReference    a reference Object that handles the connection listener
 */
public WebsocketClientHandler(URI uri, String remoteUniqueDeviceId, AtomicReference<IBlaubotIncomingConnectionListener> listenerReference) {
    // Connect with V13 (RFC 6455 aka HyBi-17).
    // other options are V08 or V00.
    // If V00 is used, ping is not supported and remember to change
    // HttpResponseDecoder to WebSocketHttpResponseDecoder in the pipeline.
    this.handshaker = WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders(), BlaubotWebsocketAdapter.MAX_WEBSOCKET_FRAME_SIZE);
    this.remoteDeviceUniqueDeviceId = remoteUniqueDeviceId;
    this.incomingConnectionListenerReference = listenerReference;
}
 
開發者ID:Blaubot,項目名稱:Blaubot,代碼行數:16,代碼來源:WebsocketClientHandler.java


注:本文中的io.netty.handler.codec.http.websocketx.WebSocketVersion類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。