javax.websocket.Session.getBasicRemote()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(2319)

本文整理了Java中javax.websocket.Session.getBasicRemote()方法的一些代码示例,展示了Session.getBasicRemote()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Session.getBasicRemote()方法的具体详情如下:
包路径:javax.websocket.Session
类名称:Session
方法名:getBasicRemote

Session.getBasicRemote介绍

[英]Return a reference a RemoteEndpoint object representing the peer of this conversation that is able to send messages synchronously to the peer.
[中]返回对远程端点对象的引用,该对象表示该对话的对等方,该对等方能够同步向该对等方发送消息。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
protected void sendPongMessage(PongMessage message) throws IOException {
  getNativeSession().getBasicRemote().sendPong(message.getPayload());
}

代码示例来源:origin: spring-projects/spring-framework

@Override
protected void sendPingMessage(PingMessage message) throws IOException {
  getNativeSession().getBasicRemote().sendPing(message.getPayload());
}

代码示例来源:origin: confluentinc/ksql

@Override
public void onSchema(final Schema schema) {
 try {
  session.getBasicRemote().sendText(
    mapper.writeValueAsString(EntityUtil.buildSourceSchemaEntity(schema))
  );
 } catch (final IOException e) {
  log.error("Error sending schema", e);
  SessionUtil.closeSilently(session, CloseCodes.PROTOCOL_ERROR, "Unable to send schema");
 }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
protected void sendTextMessage(TextMessage message) throws IOException {
  getNativeSession().getBasicRemote().sendText(message.getPayload(), message.isLast());
}

代码示例来源:origin: spring-projects/spring-framework

@Override
protected void sendBinaryMessage(BinaryMessage message) throws IOException {
  getNativeSession().getBasicRemote().sendBinary(message.getPayload(), message.isLast());
}

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * Send a stop message to server as result of user request.
 */
public void sendMessage( StopMessage stopMessage ) throws KettleException {
 sessionValid();
 try {
  if ( !alReadySendedStopMessage.getAndSet( true ) ) {
   this.userSession.getBasicRemote().sendObject( stopMessage );
  }
 } catch ( Exception e ) {
  throw new KettleException( e );
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * Send a execution request message.
 */
public void sendMessage( ExecutionRequest request ) throws KettleException {
 sessionValid();
 try {
  request.setReuseSparkContext( reuseSparkContext );
  this.userSession.getBasicRemote().sendObject( request );
 } catch ( Exception e ) {
  throw new KettleException( e );
 }
}

代码示例来源:origin: apache/incubator-pinot

session.getBasicRemote().sendText("");
} catch (IOException e) {

代码示例来源:origin: glyptodon/guacamole-client

remote = session.getBasicRemote();

代码示例来源:origin: mercyblitz/segmentfault-lessons

private void sendText(Session session, String message) {
  RemoteEndpoint.Basic basic = session.getBasicRemote();
  try {
    basic.sendText(message);
  } catch (IOException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: opensourceBIM/BIMserver

@Override
public void sendBlocking(byte[] data, int start, int length) throws IOException {
  synchronized (this) {
    try {
      websocketSession.getBasicRemote().sendBinary(ByteBuffer.wrap(data, start, length));
    } catch (IOException e) {
      // Ignore
    }
  }
}

代码示例来源:origin: yizhiwazi/springboot-socks

/**
 * 公共方法:发送信息给所有人
 */
private static void sendMessageToAll(String msg) {
  onlineSessions.forEach((id, session) -> {
    try {
      session.getBasicRemote().sendText(msg);
    } catch (IOException e) {
      e.printStackTrace();
    }
  });
}

代码示例来源:origin: opensourceBIM/BIMserver

@Override
public void sendBlocking(ByteBuffer data) throws IOException {
  synchronized (this) {
    try {
      websocketSession.getBasicRemote().sendBinary(data);
    } catch (IOException e) {
      // Ignore
    }
  }
}

代码示例来源:origin: zhangyd-c/springboot-learning

public void sendMessage(String message) throws IOException {
    this.session.getBasicRemote().sendText(message);
  }
}

代码示例来源:origin: opensourceBIM/BIMserver

public OutputStream getSendStream() throws IOException {
  return websocketSession.getBasicRemote().getSendStream();
}

代码示例来源:origin: FlowCI/flow-platform

private void sendRealTimeLog(Log log) {
  if (wsSession == null) {
    return;
  }
  try {
    String format = websocketLogFormat(log);
    wsSession.getBasicRemote().sendText(format);
    LogEventHandler.log.debug("Log sent: {}", format);
  } catch (Throwable e) {
    LogEventHandler.log.warn("Fail to send real time log to queue");
  }
}

代码示例来源:origin: crashub/crash

private void send(Event event) {
  try {
   wsSession.getBasicRemote().sendText(event.toJSON());
  }
  catch (IOException e) {
   e.printStackTrace();
  }
 }
}

代码示例来源:origin: confluentinc/ksql

@Test
public void testOnSchema() throws Exception {
 replayOnSubscribe();
 session.getBasicRemote();
 EasyMock.expectLastCall().andReturn(basic).once();
 final Capture<String> schema = EasyMock.newCapture();
 basic.sendText(EasyMock.capture(schema));
 EasyMock.expectLastCall().andThrow(new IOException("bad bad io")).once();
 final Capture<CloseReason> reason = EasyMock.newCapture();
 session.close(EasyMock.capture(reason));
 subscription.cancel();
 EasyMock.replay(subscription, session, basic);
 subscriber.onSchema(SchemaBuilder
             .struct()
   .field("currency", Schema.STRING_SCHEMA)
   .field("amount", Schema.OPTIONAL_FLOAT32_SCHEMA)
             .build());
 subscriber.close();
 assertEquals(
   "[" +
     "{\"name\":\"currency\"," +
     "\"schema\":{\"type\":\"STRING\",\"fields\":null,\"memberSchema\":null}}," +
     "{\"name\":\"amount\"," +
     "\"schema\":{\"type\":\"DOUBLE\",\"fields\":null,\"memberSchema\":null}}]"
   , schema.getValue());
 assertEquals("Unable to send schema", reason.getValue().getReasonPhrase());
 assertEquals(CloseCodes.PROTOCOL_ERROR, reason.getValue().getCloseCode());
 EasyMock.verify(subscription, session, basic);
}

代码示例来源:origin: opensourceBIM/BIMserver

@Override
public void send(JsonNode request) {
  synchronized (this) {
    if (websocketSession.isOpen()) {
      try {
        websocketSession.getBasicRemote().sendText(request.toString());
      } catch (Exception e) {
        // Skip
      }
    } else {
      streamer.onClose();
    }
  }
}

代码示例来源:origin: apache/wicket

@Override
public synchronized IWebSocketConnection sendMessage(byte[] message, int offset, int length)
  throws IOException
{
  checkClosed();
  ByteBuffer buf = ByteBuffer.wrap(message, offset, length);
  session.getBasicRemote().sendBinary(buf);
  return this;
}

相关文章