Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <a href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/websocket/api/Session.html" rel="nofollow">Session</a> object you get in your method parameters contains the scope of your conversation with the remote endpoint.</p> <p>You'll want to use the <a href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/websocket/api/RemoteEndpoint.html" rel="nofollow">RemoteEndpoint</a> that the <a href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/websocket/api/Session.html#getRemote%28%29" rel="nofollow">Session.getRemote()</a> returns in order to send messages.</p> <p>Examples:</p> <pre class="lang-java prettyprint-override"><code>// Send BINARY websocket message (async) byte data[] = mapper.toBytes(obj); session.getRemote().sendBytesByFuture(data); // Send TEXT websocket message (async) String text = mapper.toString(obj); session.getRemote().sendStringByFuture(text); </code></pre> <p>Be aware though that the session.getRemote() call will throw a WebSocketException if the remote endpoint connection is no longer in an open state (such as the case where the remote endpoint send you a message and then immediately initiated a CLOSE handshake control message).</p> <pre class="lang-java prettyprint-override"><code>// How to handle send message if remote isn't there try { // Send message to remote session.getRemote().sendString(text); } catch(WebSocketException e) { // WebSocket remote isn't available. // The connection is likely closed or in the process of closing. } </code></pre> <p>Note: this style of websocket use, where you have a Session and a RemoteEndpoint is consistent with the upcoming JSR-356 standard (<code>javax.websocket</code>). In the standard API you will have <code>javax.websocket.Session</code> and <code>javax.websocket.RemoteEndpoint</code> to work with.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload