Search in sources :

Example 11 with RemoteEndpoint

use of org.eclipse.jetty.websocket.api.RemoteEndpoint in project jetty.project by eclipse.

the class SessionSocket method sendString.

protected void sendString(String text) throws IOException {
    RemoteEndpoint remote = session.getRemote();
    remote.sendString(text, null);
    if (remote.getBatchMode() == BatchMode.ON)
        remote.flush();
}
Also used : RemoteEndpoint(org.eclipse.jetty.websocket.api.RemoteEndpoint)

Example 12 with RemoteEndpoint

use of org.eclipse.jetty.websocket.api.RemoteEndpoint in project jetty.project by eclipse.

the class BigEchoSocket method onBinary.

@OnWebSocketMessage
public void onBinary(Session session, byte[] buf, int offset, int length) throws IOException {
    if (!session.isOpen()) {
        LOG.warn("Session is closed");
        return;
    }
    RemoteEndpoint remote = session.getRemote();
    remote.sendBytes(ByteBuffer.wrap(buf, offset, length), null);
    if (remote.getBatchMode() == BatchMode.ON)
        remote.flush();
}
Also used : RemoteEndpoint(org.eclipse.jetty.websocket.api.RemoteEndpoint) OnWebSocketMessage(org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage)

Example 13 with RemoteEndpoint

use of org.eclipse.jetty.websocket.api.RemoteEndpoint in project jetty.project by eclipse.

the class EchoSocket method onBinary.

@OnWebSocketMessage
public void onBinary(byte[] buf, int offset, int len) throws IOException {
    LOG.debug("onBinary(byte[{}],{},{})", buf.length, offset, len);
    // echo the message back.
    ByteBuffer data = ByteBuffer.wrap(buf, offset, len);
    RemoteEndpoint remote = this.session.getRemote();
    remote.sendBytes(data, null);
    if (remote.getBatchMode() == BatchMode.ON)
        remote.flush();
}
Also used : RemoteEndpoint(org.eclipse.jetty.websocket.api.RemoteEndpoint) ByteBuffer(java.nio.ByteBuffer) OnWebSocketMessage(org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage)

Example 14 with RemoteEndpoint

use of org.eclipse.jetty.websocket.api.RemoteEndpoint in project jetty.project by eclipse.

the class EchoSocket method onText.

@OnWebSocketMessage
public void onText(String message) throws IOException {
    LOG.debug("onText({})", message);
    // echo the message back.
    RemoteEndpoint remote = session.getRemote();
    remote.sendString(message, null);
    if (remote.getBatchMode() == BatchMode.ON)
        remote.flush();
}
Also used : RemoteEndpoint(org.eclipse.jetty.websocket.api.RemoteEndpoint) OnWebSocketMessage(org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage)

Example 15 with RemoteEndpoint

use of org.eclipse.jetty.websocket.api.RemoteEndpoint in project jetty.project by eclipse.

the class RFCSocket method onBinary.

@OnWebSocketMessage
public void onBinary(byte[] buf, int offset, int len) throws IOException {
    LOG.debug("onBinary(byte[{}],{},{})", buf.length, offset, len);
    // echo the message back.
    ByteBuffer data = ByteBuffer.wrap(buf, offset, len);
    RemoteEndpoint remote = session.getRemote();
    remote.sendBytes(data, null);
    if (remote.getBatchMode() == BatchMode.ON)
        remote.flush();
}
Also used : RemoteEndpoint(org.eclipse.jetty.websocket.api.RemoteEndpoint) ByteBuffer(java.nio.ByteBuffer) OnWebSocketMessage(org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage)

Aggregations

RemoteEndpoint (org.eclipse.jetty.websocket.api.RemoteEndpoint)20 OnWebSocketMessage (org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage)7 URI (java.net.URI)6 Session (org.eclipse.jetty.websocket.api.Session)6 Test (org.junit.Test)6 IOException (java.io.IOException)4 ByteBuffer (java.nio.ByteBuffer)3 RuntimeIOException (org.eclipse.jetty.io.RuntimeIOException)3 WebSocketClient (org.eclipse.jetty.websocket.client.WebSocketClient)3 CaptureSocket (org.eclipse.jetty.websocket.server.helper.CaptureSocket)3 WebSocketSession (org.eclipse.jetty.websocket.common.WebSocketSession)2 IBlockheadServerConnection (org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 WebSocketAdapter (org.eclipse.jetty.websocket.api.WebSocketAdapter)1 OnWebSocketFrame (org.eclipse.jetty.websocket.api.annotations.OnWebSocketFrame)1 Ignore (org.junit.Ignore)1