Java Code Examples for org.eclipse.jetty.websocket.api.RemoteEndpoint#sendString()

The following examples show how to use org.eclipse.jetty.websocket.api.RemoteEndpoint#sendString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebSocketSessionImpl.java    From purplejs with Apache License 2.0 6 votes vote down vote up
@Override
public void send( final String message )
{
    final RemoteEndpoint endpoint = getRemote();
    if ( endpoint == null )
    {
        return;
    }

    try
    {
        endpoint.sendString( message );
    }
    catch ( final Exception e )
    {
        LOG.log( Level.SEVERE, "Failed to send web-socket message", e );
    }
}
 
Example 2
Source File: WebSocketRunner.java    From codenjoy with GNU General Public License v3.0 6 votes vote down vote up
@OnWebSocketMessage
public void onMessage(String data) {
    try {
        Matcher matcher = BOARD_PATTERN.matcher(data);
        if (!matcher.matches()) {
            throw new IllegalArgumentException("Unexpected board format, should be: " + BOARD_FORMAT);
        }

        board.forString(matcher.group(1));
        print("Board: \n" + board);

        String answer = solver.get(board);
        print("Answer: " + answer);

        RemoteEndpoint remote = session.getRemote();
        if (remote == null) { // TODO to understand why this can happen?
            WebSocketRunner.this.tryToConnect();
            return;
        }
        remote.sendString(answer);
    } catch (Exception e) {
        print("Error processing data: " + data);
        print(e);
    }
    printBreak();
}
 
Example 3
Source File: EchoSocket.java    From knox with Apache License 2.0 6 votes vote down vote up
@Override
public void onWebSocketText(String message) {
  if (isNotConnected()) {
    return;
  }

  try {
    RemoteEndpoint remote = getRemote();
    remote.sendString(message, null);
    if (remote.getBatchMode() == BatchMode.ON) {
      remote.flush();
    }
  } catch (IOException x) {
    throw new RuntimeIOException(x);
  }
}
 
Example 4
Source File: BrowserVisualization.java    From coordination_oru with GNU General Public License v3.0 5 votes vote down vote up
private void sendMessage(String text) {
	if (BrowserVisualizationSocket.ENDPOINTS != null) {
		for (RemoteEndpoint rep : BrowserVisualizationSocket.ENDPOINTS) {
			try {
				rep.sendString(text);
			}
			catch(IOException e) { e.printStackTrace(); }
		}
	}
}
 
Example 5
Source File: ProxyWebSocketAdapter.java    From knox with Apache License 2.0 5 votes vote down vote up
private void flushBufferedMessages(final RemoteEndpoint remote) throws IOException {
  LOG.debugLog("Flushing old buffered messages");
  for(String obj:messageBuffer) {
    LOG.debugLog("Sending old buffered message [From Backend <---]: " + obj);
    remote.sendString(obj);
  }
  messageBuffer.clear();
}
 
Example 6
Source File: WebsocketServerInitiatedMessageTest.java    From knox with Apache License 2.0 5 votes vote down vote up
@Override
public void onWebSocketConnect(Session sess) {
  super.onWebSocketConnect(sess);

  try {
    RemoteEndpoint remote = getRemote();
    remote.sendString("echo", null);
    if (remote.getBatchMode() == BatchMode.ON) {
      remote.flush();
    }
  } catch (IOException x) {
    throw new RuntimeIOException(x);
  }
}