use of io.netty.handler.codec.http.websocketx.CloseWebSocketFrame in project vert.x by eclipse.
the class ServerConnection method close.
@Override
public void close() {
if (handshaker == null) {
super.close();
} else {
endReadAndFlush();
handshaker.close(channel, new CloseWebSocketFrame(1000, null));
}
}
use of io.netty.handler.codec.http.websocketx.CloseWebSocketFrame in project ratpack by ratpack.
the class DefaultWebSocket method close.
@Override
public void close(int statusCode, String reason) {
open.set(false);
channel.writeAndFlush(new CloseWebSocketFrame(statusCode, reason));
channel.close().addListener(future -> onClose.run());
}
use of io.netty.handler.codec.http.websocketx.CloseWebSocketFrame in project reactor-netty by reactor.
the class HttpClientWSOperations method sendClose.
void sendClose(CloseWebSocketFrame frame) {
if (frame != null && !frame.isFinalFragment()) {
channel().writeAndFlush(frame);
return;
}
if (CLOSE_SENT.getAndSet(this, 1) == 0) {
ChannelFuture f = channel().writeAndFlush(frame == null ? new CloseWebSocketFrame() : frame);
f.addListener(ChannelFutureListener.CLOSE);
}
}
use of io.netty.handler.codec.http.websocketx.CloseWebSocketFrame in project reactor-netty by reactor.
the class HttpClientWSOperations method onInboundNext.
@Override
@SuppressWarnings("unchecked")
public void onInboundNext(ChannelHandlerContext ctx, Object msg) {
if (msg instanceof FullHttpResponse) {
started = true;
channel().pipeline().remove(HttpObjectAggregator.class);
FullHttpResponse response = (FullHttpResponse) msg;
setNettyResponse(response);
if (checkResponseCode(response)) {
try {
if (!handshaker.isHandshakeComplete()) {
handshaker.finishHandshake(channel(), response);
}
} catch (WebSocketHandshakeException wshe) {
if (serverError) {
onInboundError(wshe);
return;
}
} finally {
// Release unused content (101 status)
response.content().release();
}
parentContext().fireContextActive(this);
handshakerResult.trySuccess();
}
return;
}
if (msg instanceof PingWebSocketFrame) {
channel().writeAndFlush(new PongWebSocketFrame(((PingWebSocketFrame) msg).content()));
ctx.read();
return;
}
if (msg instanceof CloseWebSocketFrame && ((CloseWebSocketFrame) msg).isFinalFragment()) {
if (log.isDebugEnabled()) {
log.debug("CloseWebSocketFrame detected. Closing Websocket");
}
CloseWebSocketFrame close = (CloseWebSocketFrame) msg;
sendClose(new CloseWebSocketFrame(true, close.rsv(), close.content()));
} else {
super.onInboundNext(ctx, msg);
}
}
use of io.netty.handler.codec.http.websocketx.CloseWebSocketFrame in project ballerina by ballerina-lang.
the class WebSocketClientHandler method channelRead0.
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
Channel ch = ctx.channel();
if (!handshaker.isHandshakeComplete()) {
handshaker.finishHandshake(ch, (FullHttpResponse) msg);
logger.info("WebSocket Client connected!");
handshakeFuture.setSuccess();
isOpen = true;
return;
}
if (msg instanceof FullHttpResponse) {
FullHttpResponse response = (FullHttpResponse) msg;
throw new IllegalStateException("Unexpected FullHttpResponse (getStatus=" + response.status() + ", content=" + response.content().toString(CharsetUtil.UTF_8) + ')');
}
WebSocketFrame frame = (WebSocketFrame) msg;
if (frame instanceof TextWebSocketFrame) {
TextWebSocketFrame textFrame = (TextWebSocketFrame) frame;
textReceived = textFrame.text();
} else if (frame instanceof BinaryWebSocketFrame) {
BinaryWebSocketFrame binaryFrame = (BinaryWebSocketFrame) frame;
bufferReceived = binaryFrame.content().nioBuffer();
} else if (frame instanceof PingWebSocketFrame) {
PingWebSocketFrame pingFrame = (PingWebSocketFrame) frame;
isPing = true;
bufferReceived = pingFrame.content().nioBuffer();
} else if (frame instanceof PongWebSocketFrame) {
PongWebSocketFrame pongFrame = (PongWebSocketFrame) frame;
isPong = true;
bufferReceived = pongFrame.content().nioBuffer();
} else if (frame instanceof CloseWebSocketFrame) {
ch.close().sync();
isOpen = false;
}
}
Aggregations