@Override
public void handleEvent(final WebSocketChannel channel) {
try {
final StreamSourceFrameChannel ws = channel.receive();
if (ws != null) {
StreamSinkFrameChannel target;
if (ws.getType() == WebSocketFrameType.PING ||
ws.getType() == WebSocketFrameType.CLOSE) {
target = channel.send(ws.getType() == WebSocketFrameType.PING ? WebSocketFrameType.PONG : WebSocketFrameType.CLOSE);
} else if (ws.getType() == WebSocketFrameType.PONG) {
ws.getReadSetter().set(ChannelListeners.drainListener(Long.MAX_VALUE, null, null));