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


Java WebSocketServerHandshakerFactory.sendUnsupportedWebSocketVersionResponse方法代碼示例

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


在下文中一共展示了WebSocketServerHandshakerFactory.sendUnsupportedWebSocketVersionResponse方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleHttpRequest

import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory; //導入方法依賴的package包/類
private void handleHttpRequest(ChannelHandlerContext ctx,
		FullHttpRequest req) {
	if (!req.getDecoderResult().isSuccess()
			|| (!"websocket".equals(req.headers().get("Upgrade")))) {
		sendHttpResponse(ctx, req, new DefaultFullHttpResponse(
				HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST));
		return;
	}
	WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
			"ws://localhost:7777/websocket", null, false);
	socketServerHandshaker = wsFactory.newHandshaker(req);
	if (socketServerHandshaker == null) {
		WebSocketServerHandshakerFactory
				.sendUnsupportedWebSocketVersionResponse(ctx.channel());
	} else {
		socketServerHandshaker.handshake(ctx.channel(), req);
	}
}
 
開發者ID:hdcuican,項目名稱:java_learn,代碼行數:19,代碼來源:WebSocketServerHandler.java

示例2: handleHttpRequest

import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory; //導入方法依賴的package包/類
private void handleHttpRequest(ChannelHandlerContext ctx,
    FullHttpRequest req) throws Exception {

// 如果HTTP解碼失敗,返回HHTP異常
if (!req.getDecoderResult().isSuccess()
	|| (!"websocket".equals(req.headers().get("Upgrade")))) {
    sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1,
	    BAD_REQUEST));
    return;
}

// 構造握手響應返回,本機測試
WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
	"ws://localhost:8080/websocket", null, false);
handshaker = wsFactory.newHandshaker(req);
if (handshaker == null) {
    WebSocketServerHandshakerFactory
	    .sendUnsupportedWebSocketVersionResponse(ctx.channel());
} else {
    handshaker.handshake(ctx.channel(), req);
}
   }
 
開發者ID:changyuefeng,項目名稱:netty-book,代碼行數:23,代碼來源:WebSocketServerHandler.java

示例3: handleHttpRequest

import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory; //導入方法依賴的package包/類
public void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest req) {
	if (!req.getDecoderResult().isSuccess() || !"websocket".equals(req.headers().get("Upgrade"))) {
		sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST));
		return;
	}

	// 構造握手響應返回,本機測試
	WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory("ws://localhost:8080/websocket", null,
			false);

	handshaker = wsFactory.newHandshaker(req);

	if (handshaker == null) {
		WebSocketServerHandshakerFactory.sendUnsupportedWebSocketVersionResponse(ctx.channel());
	} else {
		handshaker.handshake(ctx.channel(), req);
	}
}
 
開發者ID:zoopaper,項目名稱:netty-study,代碼行數:19,代碼來源:WebSocketServerHandler.java

示例4: handleHttpRequest

import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory; //導入方法依賴的package包/類
private void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest req)
        throws Exception {
    // Handle a bad request.
    if (!req.getDecoderResult().isSuccess()) {
        sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, BAD_REQUEST));
        req.release();
        return;
    }

    // Allow only GET methods.
    if (req.getMethod() != GET) {
        sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, FORBIDDEN));
        req.release();
        return;
    }

    // Handshake
    WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
            getWebSocketLocation(req), null, false, Integer.MAX_VALUE);
    handshaker = wsFactory.newHandshaker(req);
    if (handshaker == null) {
        WebSocketServerHandshakerFactory.sendUnsupportedWebSocketVersionResponse(ctx.channel());
    } else {
        handshaker.handshake(ctx.channel(), req);
    }
    req.release();
}
 
開發者ID:kyle-liu,項目名稱:netty4study,代碼行數:28,代碼來源:AutobahnServerHandler.java

示例5: handleWebSocketHandshake

import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory; //導入方法依賴的package包/類
private void handleWebSocketHandshake(ChannelHandlerContext ctx, FullHttpRequest req){
    String location = "ws://" + req.headers().get(HOST) + req.getUri();

    WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
            location, null, false);
    _handshaker = wsFactory.newHandshaker(req);
    if (_handshaker == null) {
        WebSocketServerHandshakerFactory.sendUnsupportedWebSocketVersionResponse(ctx.channel());
    } else {
        _handshaker.handshake(ctx.channel(), req);
    }
    
}
 
開發者ID:InformaticaCorp,項目名稱:Surf,代碼行數:14,代碼來源:HttpServerHandler.java

示例6: channelRead0

import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory; //導入方法依賴的package包/類
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object req) throws Exception {
    if (req instanceof FullHttpRequest) {
        FullHttpRequest request = (FullHttpRequest) req;
        // ----- Client authenticity check code -----
        // !!!!! WARNING !!!!!
        // THE BELOW SECTION OF CODE CHECKS TO ENSURE THAT CONNECTIONS ARE COMING
        // FROM THE OFFICIAL AGAR.IO CLIENT. IF YOU REMOVE OR MODIFY THE BELOW
        // SECTION OF CODE TO ALLOW CONNECTIONS FROM A CLIENT ON A DIFFERENT DOMAIN,
        // YOU MAY BE COMMITTING COPYRIGHT INFRINGEMENT AND LEGAL ACTION MAY BE TAKEN
        // AGAINST YOU. THIS SECTION OF CODE WAS ADDED ON JULY 9, 2015 AT THE REQUEST
        // OF THE AGAR.IO DEVELOPERS.
        String origin = request.headers().get(HttpHeaders.ORIGIN);
        switch (origin) {
// TODO move to config
            case "http://agar.io":
            case "https://agar.io":
            case "http://localhost":
            case "https://localhost":
            case "http://127.0.0.1":
            case "https://127.0.0.1":
            case "http://ogar.pp.ua":
                break;
            default:
            	_log.info(String.format("User kicked by invalid origin! IP %s, ORIGIN %s", ctx.channel().remoteAddress(), origin));
                ctx.channel().close();
                return;
        }
        // -----/Client authenticity check code -----

        WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory("ws://" + request.headers().get(HttpHeaders.HOST) + "/", null, true);
        handshaker = wsFactory.newHandshaker(request);
        if (handshaker == null) {
            WebSocketServerHandshakerFactory.sendUnsupportedWebSocketVersionResponse(ctx.channel());
        } else {
            handshaker.handshake(ctx.channel(), request);
        }
    } else if (req instanceof WebSocketFrame) {
        WebSocketFrame frame = (WebSocketFrame) req;

        if (req instanceof CloseWebSocketFrame) {
            if (handshaker != null) {
                handshaker.close(ctx.channel(), ((CloseWebSocketFrame) req).retain());
            }
        } else if (req instanceof PingWebSocketFrame) {
            ctx.channel().write(new PongWebSocketFrame(frame.content().retain()));
        } else {
            ctx.fireChannelRead(frame.retain());
        }
    }
}
 
開發者ID:CalypsoToolz,項目名稱:FPAgar,代碼行數:52,代碼來源:WebSocketHandler.java


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