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