use of org.eclipse.jetty.websocket.api.annotations.OnWebSocketFrame in project jetty.project by eclipse.
the class EchoFragmentSocket method onFrame.
@OnWebSocketFrame
public void onFrame(Session session, Frame frame) {
if (!frame.getType().isData()) {
// Don't process non-data frames
return;
}
ByteBuffer data = frame.getPayload();
int half = data.remaining() / 2;
ByteBuffer buf1 = data.slice();
ByteBuffer buf2 = data.slice();
buf1.limit(half);
buf2.position(half);
RemoteEndpoint remote = session.getRemote();
try {
switch(frame.getType()) {
case BINARY:
remote.sendBytes(buf1, null);
remote.sendBytes(buf2, null);
break;
case TEXT:
// NOTE: This impl is not smart enough to split on a UTF8 boundary
remote.sendString(BufferUtil.toUTF8String(buf1), null);
remote.sendString(BufferUtil.toUTF8String(buf2), null);
break;
default:
throw new IOException("Unexpected frame type: " + frame.getType());
}
} catch (IOException e) {
e.printStackTrace(System.err);
}
}
use of org.eclipse.jetty.websocket.api.annotations.OnWebSocketFrame in project spring-framework by spring-projects.
the class JettyWebSocketHandlerAdapter method onWebSocketFrame.
@OnWebSocketFrame
public void onWebSocketFrame(Frame frame) {
if (this.delegateSession != null) {
if (OpCode.PONG == frame.getOpCode()) {
ByteBuffer buffer = (frame.getPayload() != null ? frame.getPayload() : EMPTY_PAYLOAD);
WebSocketMessage webSocketMessage = toMessage(Type.PONG, buffer);
delegateSession.handleMessage(webSocketMessage.getType(), webSocketMessage);
}
}
}
use of org.eclipse.jetty.websocket.api.annotations.OnWebSocketFrame in project spring-framework by spring-projects.
the class JettyWebSocketHandlerAdapter method onWebSocketFrame.
@OnWebSocketFrame
public void onWebSocketFrame(Frame frame) {
if (OpCode.PONG == frame.getOpCode()) {
ByteBuffer payload = frame.getPayload() != null ? frame.getPayload() : EMPTY_PAYLOAD;
PongMessage message = new PongMessage(payload);
try {
this.webSocketHandler.handleMessage(this.wsSession, message);
} catch (Throwable ex) {
ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
}
}
}
Aggregations