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


Java WebSocketServerProtocolHandler類代碼示例

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


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

示例1: userEventTriggered

import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //導入依賴的package包/類
@SuppressWarnings("deprecation")
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt)throws Exception {
	if (evt == WebSocketServerProtocolHandler.ServerHandshakeStateEvent.HANDSHAKE_COMPLETE)
	{//舊版本
		log.debug("excute webSocketHandComplete……");
		webSocketHandComplete(ctx);
		ctx.pipeline().remove(this);
		log.debug("excuted webSocketHandComplete:"+ctx.pipeline().toMap().toString());
		return;
	}
	if(evt instanceof HandshakeComplete)
	{//新版本
		HandshakeComplete hc=(HandshakeComplete)evt;
		log.debug("excute webSocketHandComplete……,HandshakeComplete="+hc);
		webSocketHandComplete(ctx);
		ctx.pipeline().remove(this);
		log.debug("excuted webSocketHandComplete:"+ctx.pipeline().toMap().toString());
		return;
	}
	super.userEventTriggered(ctx, evt);
}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:23,代碼來源:WebSocketServerInitializer.java

示例2: setupWSChannel

import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //導入依賴的package包/類
protected ChannelHandler setupWSChannel(SslContext sslCtx, Configuration conf, DataStore datastore) {
    return new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline().addLast("ssl", sslCtx.newHandler(ch.alloc()));
            ch.pipeline().addLast("httpServer", new HttpServerCodec());
            ch.pipeline().addLast("aggregator", new HttpObjectAggregator(8192));
            ch.pipeline().addLast("sessionExtractor", new WebSocketHttpCookieHandler(config));
            ch.pipeline().addLast("idle-handler", new IdleStateHandler(conf.getWebsocket().getTimeout(), 0, 0));
            ch.pipeline().addLast("ws-protocol", new WebSocketServerProtocolHandler(WS_PATH, null, true));
            ch.pipeline().addLast("wsDecoder", new WebSocketRequestDecoder(datastore, config));
            ch.pipeline().addLast("error", new WSExceptionHandler());
        }
    };

}
 
開發者ID:NationalSecurityAgency,項目名稱:qonduit,代碼行數:18,代碼來源:Server.java

示例3: initChannel

import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //導入依賴的package包/類
@Override
protected void initChannel(Channel ch) throws Exception {
	ChannelPipeline pipeline = ch.pipeline();
	//編解碼http請求
	pipeline.addLast(new HttpServerCodec());
	//聚合解碼HttpRequest/HttpContent/LastHttpContent到FullHttpRequest
	//保證接收的Http請求的完整性
	pipeline.addLast(new HttpObjectAggregator(64 *1024));
	//寫文件內容
	pipeline.addLast(new ChunkedWriteHandler());
	//處理FullHttpRequest
	pipeline.addLast(new HttpRequestHandler("/ws"));
	//處理其他的WebSocketFrame
	pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
	//處理TextWebSocketFrame
	pipeline.addLast(new TextWebSocketFrameHandler(group));
}
 
開發者ID:janzolau1987,項目名稱:study-netty,代碼行數:18,代碼來源:ChatServerInitializer.java

示例4: userEventTriggered

import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //導入依賴的package包/類
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
	// 如果WebSocket握手完成
	if (evt == WebSocketServerProtocolHandler.ServerHandshakeStateEvent.HANDSHAKE_COMPLETE) {
		// 刪除ChannelPipeline中的HttpRequestHttpHandler
		ctx.pipeline().remove(HttpRequestHandler.class);
		String user = ChatUtils.addChannel(ctx.channel());
		Users us = new Users(user);
		ctx.channel().writeAndFlush(new TextWebSocketFrame(us.getCurrentUser()));
		// 寫一個消息到ChannelGroup
		group.writeAndFlush(new TextWebSocketFrame(user + " 加入聊天室."));
		// 將channel添加到ChannelGroup
		group.add(ctx.channel());
		group.writeAndFlush(new TextWebSocketFrame(us.getAllUsers()));
	} else {
		super.userEventTriggered(ctx, evt);
	}
}
 
開發者ID:janzolau1987,項目名稱:study-netty,代碼行數:19,代碼來源:TextWebSocketFrameHandler.java

示例5: handleRequest

import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //導入依賴的package包/類
/**
 * Processes an HTTP request
 * @param ctx The channel handler context
 * @param req The HTTP request
 */
public void handleRequest(final ChannelHandlerContext ctx, final FullHttpRequest req) {
	log.warn("HTTP Request: {}", req);
       if (req.method() != GET) {
           sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, FORBIDDEN));
           return;
       }
       String uri = req.uri();
       if(!"/ws".equals(uri)) {
       	//channelRead(ctx, req);
       	final WebSocketServerProtocolHandler wsProto = ctx.pipeline().get(WebSocketServerProtocolHandler.class);
       	if(wsProto != null) {
       		try {
				wsProto.acceptInboundMessage(req);
				return;
			} catch (Exception ex) {
				log.error("Failed to dispatch http request to WebSocketServerProtocolHandler on channel [{}]", ctx.channel(), ex);
			}
       	}
       }
       log.error("Failed to handle HTTP Request [{}] on channel [{}]", req, ctx.channel());
       sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.MISDIRECTED_REQUEST));
}
 
開發者ID:nickman,項目名稱:HeliosStreams,代碼行數:28,代碼來源:WebSocketServiceHandler.java

示例6: decode

import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //導入依賴的package包/類
@Override
protected void decode(ChannelHandlerContext ctx, HttpObject msg, List<Object> out)
{
    if(!added && msg instanceof HttpRequest)
    {
        String path = ((HttpRequest)msg).getUri();
        WsServerHandler handler = findHandler(path);
        if(handler != null)
        {
            ctx.pipeline().addAfter("switch", "aggregator", new HttpObjectAggregator(65536));
            ctx.pipeline().addAfter("aggregator", "wsprotocol", new WebSocketServerProtocolHandler(path, null, true));
            ctx.pipeline().addAfter("wsprotocol", "wshandler", new WsFrameHandler(handler));
            added = true;
        }
    }
    ReferenceCountUtil.retain(msg);
    out.add(msg);
}
 
開發者ID:touwolf,項目名稱:bridje-framework,代碼行數:19,代碼來源:HttpWsSwitch.java

示例7: createInitializer

import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //導入依賴的package包/類
protected ChannelInitializer<Channel> createInitializer() {

	return new ChannelInitializer<Channel>() {

		@Override
		protected void initChannel(Channel ch) throws Exception {
			ChannelPipeline p = ch.pipeline();
			p.addLast(new HttpServerCodec() );
			p.addLast(new ChunkedWriteHandler());
			p.addLast(new HttpObjectAggregator(64 * 1024));
			p.addLast(new EchoServerHttpRequestHandler("/ws"));
			p.addLast(new WebSocketServerProtocolHandler("/ws"));
			p.addLast(new EchoServerWSHandler());
		}
	};
}
 
開發者ID:bekwam,項目名稱:examples-javafx-repos1,代碼行數:17,代碼來源:EchoServerWS.java

示例8: initWebSocketPipeline

import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //導入依賴的package包/類
private void initWebSocketPipeline(ChannelHandlerContext ctx, String websocketPath) {
    ChannelPipeline pipeline = ctx.pipeline();

    //websockets specific handlers
    pipeline.addLast("WSWebSocketServerProtocolHandler", new WebSocketServerProtocolHandler(websocketPath, true));
    pipeline.addLast("WSWebSocket", new WebSocketHandler(stats));
    pipeline.addLast("WSMessageDecoder", new MessageDecoder(stats));
    pipeline.addLast("WSSocketWrapper", new WebSocketWrapperEncoder());
    pipeline.addLast("WSMessageEncoder", new MessageEncoder(stats));
    pipeline.addLast("WSWebSocketGenericLoginHandler", genericLoginHandler);
    pipeline.remove(this);
    pipeline.remove(ChunkedWriteHandler.class);
    pipeline.remove(UrlReWriterHandler.class);
    pipeline.remove(StaticFileHandler.class);
    pipeline.remove(LetsEncryptHandler.class);
}
 
開發者ID:blynkkk,項目名稱:blynk-server,代碼行數:17,代碼來源:HttpAndWebSocketUnificatorHandler.java

示例9: initChannel

import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }
    if (enableGzip) {
        p.addLast(new HttpContentCompressor());
    }
    p.addLast(new HttpServerCodec(36192 * 2, 36192 * 8, 36192 * 16, false));
    p.addLast(new HttpServerExpectContinueHandler());
    p.addLast(new HttpObjectAggregator(Integer.MAX_VALUE));
    p.addLast(new ChunkedWriteHandler());
    if (enableCors) {
        CorsConfig corsConfig = CorsConfigBuilder.forAnyOrigin().allowNullOrigin().allowCredentials().build();
        p.addLast(new CorsHandler(corsConfig));
    }
    if (null != blade.webSocketPath()) {
        p.addLast(new WebSocketServerProtocolHandler(blade.webSocketPath(), null, true));
        p.addLast(new WebSockerHandler(blade));
    }
    service.scheduleWithFixedDelay(() -> date = new AsciiString(DateKit.gmtDate(LocalDateTime.now())), 1000, 1000, TimeUnit.MILLISECONDS);
    p.addLast(new HttpServerHandler());
}
 
開發者ID:lets-blade,項目名稱:blade,代碼行數:25,代碼來源:HttpServerInitializer.java

示例10: run

import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //導入依賴的package包/類
public ChannelFuture run() {

    final ServerBootstrap httpServerBootstrap = new ServerBootstrap();
    httpServerBootstrap.group(bossGroup, workerGroup)
      .channel(NioServerSocketChannel.class)
      .localAddress(new InetSocketAddress(port))
      .childHandler(new ChannelInitializer<SocketChannel>() {

        public void initChannel(final SocketChannel ch) throws Exception {
          ch.pipeline().addLast(
            new HttpResponseEncoder(),
            new HttpRequestDecoder(),
            new HttpObjectAggregator(65536),
            new WebSocketServerProtocolHandler("/debug-session"),
            new DebugProtocolHandler(debugWebsocketConfiguration));
        }

    });

    LOGG.log(Level.INFO, "starting camunda BPM debug HTTP websocket interface on port "+port+".");

    return httpServerBootstrap.bind(port);


  }
 
開發者ID:camunda,項目名稱:camunda-bpm-workbench,代碼行數:26,代碼來源:WebsocketServer.java

示例11: initChannel

import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //導入依賴的package包/類
@Override
protected void initChannel(Channel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    //Decode  bytes  to  HTTP  requests  /  encode  HTTP requests to bytes.
    pipeline.addLast(new HttpServerCodec());
    //Allows to write a file content.
    pipeline.addLast(new ChunkedWriteHandler());
    //Aggregate decoded HttpRequest / HttpContent / LastHttpContent to FullHttpRequest. This way you will always receive only full Http requests
    pipeline.addLast(new HttpObjectAggregator(64 * 1024));
    //Handle FullHttpRequest which are not send to /ws URI and so serve the index.html page
    pipeline.addLast(new HttpRequestHandler("/ws"));
    //Handle the WebSocket upgrade and Ping/Pong/Close WebSocket frames to be RFC compliant
    pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
    //Handles Text frames and handshake completion events
    pipeline.addLast(new TextWebSocketFrameHandler(group));
}
 
開發者ID:edgar615,項目名稱:javase-study,代碼行數:17,代碼來源:ChatServerInitializer.java

示例12: initChannel

import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
    ChannelPipeline pipeline = socketChannel.pipeline();
    pipeline.addLast("timeout", new ReadTimeoutHandler(15));
    pipeline.addLast("codec-http", new HttpServerCodec());
    pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
    pipeline.addLast("handler", new HTTPHandler(plugin));
    pipeline.addLast("websocket", new WebSocketServerProtocolHandler("/server"));
    pipeline.addLast("packet-decoder", new PacketDecoder());
    pipeline.addLast("packet-encoder", new PacketEncoder());
    pipeline.addLast("packet-handler", new ClientHandler(socketChannel, plugin));

    socketChannel.config().setAllocator(PooledByteBufAllocator.DEFAULT);

    plugin.getWebHandler().getChannelGroup().add(socketChannel);
}
 
開發者ID:Thinkofname,項目名稱:ThinkMap,代碼行數:17,代碼來源:ServerChannelInitializer.java

示例13: initChannel

import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //導入依賴的package包/類
@Override
public void initChannel(SocketChannel ch) {
  ChannelPipeline p = ch.pipeline();
  p.addLast(new ReadTimeoutHandler(60, TimeUnit.SECONDS));
  if (sslContext != null) {
    p.addLast(sslContext.newHandler(ch.alloc()));
  }
  p.addLast(new HttpContentCompressor(5));
  p.addLast(new HttpServerCodec());
  p.addLast(new HttpObjectAggregator(1048576));
  p.addLast(new ChunkedWriteHandler());
  if (null != corsConfig) {
    p.addLast(new CorsHandler(corsConfig));
  }
  p.addLast(new WebSocketServerCompressionHandler());
  p.addLast(new WebSocketServerProtocolHandler(webSocketPath, null, true));
  p.addLast(new LaputaServerHandler(null != sslContext, requestProcessor));
}
 
開發者ID:orctom,項目名稱:laputa,代碼行數:19,代碼來源:LaputaServerInitializer.java

示例14: initChannel

import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //導入依賴的package包/類
protected void initChannel(NioSocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    // 編解碼 http 請求
    pipeline.addLast(new HttpServerCodec());
    // 寫文件內容
    pipeline.addLast(new ChunkedWriteHandler());
    // 聚合解碼 HttpRequest/HttpContent/LastHttpContent 到 FullHttpRequest
    // 保證接收的 Http 請求的完整性
    pipeline.addLast(new HttpObjectAggregator(64 * 1024));
    // 處理其他的 WebSocketFrame
    pipeline.addLast(new WebSocketServerProtocolHandler("/chat"));
    // 處理 TextWebSocketFrame
    pipeline.addLast(protoCodec);
    pipeline.addLast(serverHandler);
}
 
開發者ID:onsoul,項目名稱:os,代碼行數:16,代碼來源:WebSocketServerInitializer.java

示例15: switchToHttp

import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //導入依賴的package包/類
private void switchToHttp(ChannelHandlerContext ctx) {
    ChannelPipeline p = ctx.pipeline();
    p.addLast(new HttpServerCodec());
    p.addLast(new HttpObjectAggregator(65536));
    p.addLast(new WebSocketServerCompressionHandler());
    p.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, "ws", true));
    p.addLast(new NetoJsonStringToMapWebSocketDecoder());
    p.addLast(new NetoMessageToWebsocketFrameEncoder());
    p.remove(this);

    // 핸들러를 다시 등록 했으므로 이벤트를 전파
    ctx.fireChannelActive();
}
 
開發者ID:veritasware,項目名稱:neto,代碼行數:14,代碼來源:ProtocolUnificationHandler.java


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