new StringReadChannelListener(exchange.getBufferPool()) {
@Override
protected void stringDone(final String string) {
try {
if (string.equals("hello")) {
new StringWriteChannelListener("world")
.setup(channel.send(WebSocketFrameType.TEXT, "world".length()));
} else {
new StringWriteChannelListener(string)
.setup(channel.send(WebSocketFrameType.TEXT, string.length()));
}
channel.sendClose();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
@Override
protected void error(final IOException e) {
try {
e.printStackTrace();
new StringWriteChannelListener("ERROR")
.setup(channel.send(WebSocketFrameType.TEXT, "ERROR".length()));
channel.sendClose();
} catch (IOException ex) {
ex.printStackTrace();
throw new RuntimeException(ex);